I decided to introduce TypeScript in my React js application.
Having a problem with a component that uses react-spring for coordinate interpolation.
BEFORE TypeScript my component was like this:
function Card() {
const [props, set] = useSpring(() => (
{
xy: [0, 0],
config: {mass: 10, tension: 550, friction: 140}
}));
const calc = (x, y) => [x - window.innerWidth / 2, y - window.innerHeight / 2]
return (
<div onMouseMove={({clientX: x, clientY: y}) => set({xy: calc(x, y)})}>
<animated.div className="card1" style={{transform: props.xy.interpolate((x,y) => `translate3d(${x / 10}px,${y / 10}px,0)`)}}/>
</div>
);
}
everything is working properly.
AFTER typeScript:
function Card() {
const [props, set] = useSpring(() => (
{
xy: [0, 0],
config: {mass: 10, tension: 550, friction: 140}
}));
const calc = (x: number, y: number) => [x - window.innerWidth / 2, y - window.innerHeight / 2]
return (
<div onMouseMove={({clientX: x, clientY: y}) => set({xy: calc(x, y)})}>
<animated.div className="card1" style={{transform: props.xy.interpolate((xy) => `translate3d(${xy[0] / 10}px,${xy[1] / 10}px,0)`)}}/>
</div>
);
}
It does not work, I have no compilation errors, simply no translation occurs. The "style" is not injected into the element.