useState hook, setState function. Accessing previous state value

后端 未结 2 1408
感情败类
感情败类 2021-01-11 12:29

Are these two equivalent? If not which is best and why?

const [count, setCount] = useState(initialCount);
2条回答
  •  佛祖请我去吃肉
    2021-01-11 12:50

    Both examples are valid and work the same. However, I suspect that a primitive operates the same as a function because JavaScript supports first-class/higher order functions. This means that functions are threated as any other variables, allowing to pass them as arguments, assign them to variables, and return them within any other function.

提交回复
热议问题