Why React Hook useState uses const and not let

前端 未结 4 655
情话喂你
情话喂你 2020-11-30 13:21

The standard way to use a React useState Hook is the following:

const [count, setCount] = useState(0);

However this const count

4条回答
  •  无人及你
    2020-11-30 14:23

    After calling setCount the component is rerendered and the new call of useState returns the new value. The point is that count is immutable. So there's no typo here.

    Technically it is a new variable at every render.

    Source: React Github issue: Docs - Hooks: is that const a typo ?

提交回复
热议问题