I know a lot of people think that way. But that's just a syntax consideration. Reactive JavaScript libraries predate getter/setters and proxies. Like Knockout or earlier versions of Svelte, or countless other examples.
Does this hook make React any more or less reactive?
functionuseAssignableState(init){const[state,setState]=useState(init);return{getvalue(){returnstate;}setvalue(v){setState(v);}}}// use like:constcount=useAssignableState(5);count.value++:
All of these do scheduling in the background depending on the library they are present in and are effectively identical:
Calling setState gives you no more or less guarantees than assigning a value in Svelte or Vue. It means that at minimum sometime in the future the state of your application will reflect this change. Calling setState 10 times or assigning 10 different values is all the same for the libraries we are talking about.
I respect syntax preferences and there are direct consequences to opting into single primitives versus the clear read/write segregation of React. But none of this has to do with reactivity.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I know a lot of people think that way. But that's just a syntax consideration. Reactive JavaScript libraries predate getter/setters and proxies. Like Knockout or earlier versions of Svelte, or countless other examples.
Does this hook make React any more or less reactive?
All of these do scheduling in the background depending on the library they are present in and are effectively identical:
Calling
setState
gives you no more or less guarantees than assigning a value in Svelte or Vue. It means that at minimum sometime in the future the state of your application will reflect this change. CallingsetState
10 times or assigning 10 different values is all the same for the libraries we are talking about.I respect syntax preferences and there are direct consequences to opting into single primitives versus the clear read/write segregation of React. But none of this has to do with reactivity.