Redux: Replacing state

Created on 17 Oct 2015  路  2Comments  路  Source: reduxjs/redux

If I get the state object with store.getState() is there a method I can call to replace the state with a state object?

I am wondering if I can achieve something like this https://www.youtube.com/watch?v=5yHFTN-_mOo

I know I can pass the initial state as the second argument to finalCreateStore but I want to be able to update the state after redux is instantiated

All 2 comments

No this is not possible. The only way to update your state is to go through actions. You could create a special HYDRATE action though, which each of your reducers could handle. You would pass an object just like your initial state to it and each reducer would just return the object for its own key - essentially replacing the whole state (or partial state depending on your implementation).

Was this page helpful?
0 / 5 - 0 ratings