Javascript/React:如何为循环中的钩子创建动态变量名?
我正在尝试使用useAnimation()hook为一组div设置动画,如Javascript/React:如何为循环中的钩子创建动态变量名?,javascript,reactjs,Javascript,Reactjs,我正在尝试使用useAnimation()hook为一组div设置动画,如 const anim0 = useAnimation() const anim1 = useAnimation() const anim2 = useAnimation() const anim3 = useAnimation() ... 有没有更简单的方法在循环中创建此项?改用数组: const animations = Array.from( { length: 4 }, useAnimation );
const anim0 = useAnimation()
const anim1 = useAnimation()
const anim2 = useAnimation()
const anim3 = useAnimation()
...
有没有更简单的方法在循环中创建此项?改用数组:
const animations = Array.from(
{ length: 4 },
useAnimation
);
然后引用,例如,动画[0]
而不是anim0
使用数组:
const animations = Array.from(
{ length: 4 },
useAnimation
);
然后引用,例如,animations[0]
而不是anim0