Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript/React:如何为循环中的钩子创建动态变量名?_Javascript_Reactjs - Fatal编程技术网

Javascript/React:如何为循环中的钩子创建动态变量名?

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 );

我正在尝试使用useAnimation()hook为一组div设置动画,如

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