News for hackers. Stuff that matters.
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.
Re:Ask HN: How come, const variable can be modified in react by dee8717 on Thursday September 01, 2022 @01:38AM (#32672417)
Thanks, that makes some sense.
Re:Ask HN: How come, const variable can be modified in react by detaro on Wednesday August 31, 2022 @12:49PM (#32664913)
It's very unclear what you mean, but I suspect the answer is something along the lines of "you are not modifying the variable, you are creating a new one with the same name"