【发布时间】:2021-01-06 03:16:12
【问题描述】:
与 Spring 文档中提到的相反,useSpring 不会在道具更改时为我的计数器组件设置动画:
如果您使用更改的道具重新渲染组件,动画将更新。
我尝试将道具作为孩子传递,但没有效果。我错过了什么?这是一个演示: https://codesandbox.io/s/spring-counter-jsylq?file=/src/App.js:199-230
import React, { useState } from "react";
import { animated, useSpring } from "react-spring";
const Counter = ({ value }) => {
const anim = useSpring({ from: { opacity: 0 }, to: { opacity: 1 } });
return <animated.h1 style={anim}>{value}</animated.h1>;
};
export default function App() {
const [count, setCount] = useState(0);
return (
<>
<Counter value={count} />
<button onClick={() => setCount(count + 1)}>increment</button>
</>
);
}
【问题讨论】:
标签: reactjs react-spring