Why React Hook useState uses const and not let

前端 未结 4 653
情话喂你
情话喂你 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:11

    const is a guard against reassigning the value of the reference within the same scope.

    From MDN

    It does not mean the value it holds is immutable, just that the variable identifier cannot be reassigned.

    Also

    A constant cannot share its name with a function or a variable in the same scope.

提交回复
热议问题