Closed fini closed 2 years ago
state
update will constantly be refreshed at the next re-render (same as useState
), getState function is basically accessing the internal state directly which explains why it's working.
state
update will constantly be refreshed at the next re-render (same asuseState
), getState function is basically accessing the internal state directly which explains why it's working.
Thanks for your reply, I am using it to update every change in a React Hook Form on the server, and it seems I am not waiting until next re-render ;) So I will use getState() for this feature then. Thanks for your great work.
Glad you find getState
useful. 🙏
Yesterday I had an issue where I updated some state data, and I could see it was updated in the localStorage, but my state variable wasn't updating. I then had to use getState() in my function which worked. I always assumed the state variable would be up to date. Am I missing something? Code snippets below: