chdyiboke / weekly

issue and share weekly
5 stars 1 forks source link

为什么useState可以使用const解构赋值? #49

Open chdyiboke opened 3 years ago

chdyiboke commented 3 years ago

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

为什么变量没有定义为let count?

重新呈现组件后,将再次执行该函数,从而创建新的作用域,创建新的count变量,该变量与先前的变量无关。

知乎解答

chdyiboke commented 3 years ago

从断点看,每次进来都会重新的变量和值。