How could you replace the state of a store consisting of multiple slices with some other, new state in react using redux toolkit?
You can revert the whole store to its initial state using extraReducers: could the same mechanism be used to change the store state to something else then the initial state?
For example, you would have something like this:
const aSlice = createSlice({
name: 'a',
initialState: {a: 1},
reducers: {
someReducer(state, action) {...}
}
})
const bSlice = createSlice({
name: 'b',
initialState: {b: 'foo'},
reducers: {}
})
const store = configureStore({
reducer: {
aReducer: aSlice.reducer,
bReducer: bSlice.reducer,
}
});
export type RootState = ReturnType<typeof store.getState>
In a react component you can update the state with:
const dispatch = useDispatch();
dispatch(someReducer({...}));
How would you replace the state of the whole store with something like this:
{
"aReducer": {"a": 2},
"bReducer": {"b": "bar"},
}