react-spring: Interpolation doesn't work with useChain hooks API
š Bug Report
When using the useChain hooks API, interpolation doesnāt work.
To Reproduce
I have a relatively simple animation that I want to run sequentially using the useChain API. I have just converted my wrapperProps spring to use a ref and this has resulted in my width interpolation animation breaking:
Breaking Snippet
width: wrapperProps.width.interpolate(value => `${value}%`)
Full code
import React, { useRef } from 'react';
import { NavLink } from 'react-router-dom';
import { useSpring, useChain, animated } from 'react-spring';
import { animationConfig } from './sideNav.config';
export default function SideNavNavLink({
hasChildren,
icon,
isIconView,
title,
url,
visible
}) {
const tabIndex = visible ? undefined : -1;
const titleAttr = (isIconView && title) || undefined;
const wrapperRef = useRef();
const wrapperProps = useSpring({
config: animationConfig,
ref: wrapperRef,
opacity: isIconView ? 0 : 1,
width: isIconView ? 0 : 100
});
const titleRef = useRef();
const titleProps = useSpring({
display: isIconView ? 'none' : 'block',
ref: titleRef
});
// Chain animation order
useChain([wrapperRef, titleRef]);
return (
<NavLink
className="side-nav__nav-link"
to={url}
tabIndex={tabIndex}
title={titleAttr}
>
{icon && (
<img
className="side-nav__nav-link__icon"
src={`${process.env.PUBLIC_URL}${icon}`}
alt=""
/>
)}
<animated.div
className="side-nav__title-animation-wrapper"
style={{
...wrapperProps,
width: wrapperProps.width.interpolate(value => `${value}%`)
}}
>
<animated.span
className="side-nav__nav-link__title"
style={{ ...titleProps }}
>
{title}
</animated.span>
{hasChildren && hasChildren.length > 0 && (
<span className="side-nav__nav-link__collapse-icon" />
)}
</animated.div>
</NavLink>
);
}
This results in āCannot read property āinterpolateā of undefinedā whereas if I take the ref out it works fine but I canāt chain my springs.
Iāve tried changing the values to ā0%ā and ā100%ā and whilst this solved the error by taking out the interpolate statement, the animation jumps from 0% to 100% and doesnāt interpolate the in between values.
Expected behavior
I would expect to be able to still perform interpolation with my values.
Environment
react-spring
v8.0.19react
v16.8.6
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (15 by maintainers)
Commits related to this issue
- fix(choropleth): add missing domain prop to typings (#634) — committed to cameron-martin/react-spring by rccoe 5 years ago
Can confirm v9.0.0 fixes my issue.
That error often occurs when two React versions exist in the same bundle. To save you the trouble, Iāll check this out today. š