store.setState() api method doesn't trigger persistance
See original GitHub issueI’m trying to use persistance middleware in React, however I’m doing store updates from outside a react component by calling useStore.setState({ property: value })
. This function call sets the state and appears in Redux devtools without persisting the update in localStorage
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (7 by maintainers)
Top Results From Across the Web
Calling setState without triggering re-render - Stack Overflow
while this solution works and new render won't be called, I would strongly advise against modifying state directly and using setState() every ...
Read more >How to Save State to LocalStorage & Persist on Refresh with ...
LocalStorage is a browser API that allows developers to store data ... news is this method will work for any data that you...
Read more >How To Manage State in React with Redux - DigitalOcean
Redux is a popular data store for JavaScript and React applications. ... to work offline and load faster, you can change // unregister()...
Read more >Recipes - Zustand Documentation - Pmndrs.docs
You can, but bear in mind that it will cause the component to update on every state change! const state = useStore(). Selecting...
Read more >Accessing React State right after setting it - DEV Community
Yes but No, at this point, you are just praying ) that setState ... be able to access event argument as shown in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, I think that’s only the option.
devtools
middleware has this code:I’m pretty sure if there’s just one
persist
middleware alone, it works fine. When we chain multiple middleware, we need to be careful.I’m not sure. We’ll definitely need to modify some bits in
vanilla.ts -> create()
. An option would be to modify the store’s internal api object via the middleware (same thing asset
) and then use it increate()
. But I’m not sure how this could be done, I’ll check later in the day.