Re:Ask HN: How come, const variable can be modified in react
by IceMetalPunk on Wednesday August 31, 2022 @01:26PM
(#32665502)
When you have something like `const [variable, setVariable] = setState('foobar')`, you are not getting "variable" back directly. Instead, you're getting a pair of a setter function and a getter function. React keeps track of the variable's value internally, and when you access `variable` you're really just calling a getter function that "requests" the value from React, essentially. So you can can call `setVariable` to modify the value internally to React without actually changing the binding of the variable you see, hence it can be const.
[ Parent
| on HN ]