I have a project where half of it was made with classes, and the other half is being made with hooks and Redux.
For this, I have created a store with configureStore() from Redux Toolkit and provided it using the Provider component. In a very minimal way, the store is set up as follows:
const userSlice = createSlice({
name: 'user',
initialState: {
user: {}
},
reducers: {
validate: (state, action) => state.user = action.payload
}
})
const store configureStore({
reducer: {
user: userSlice.reducer
}
})
There are two components - a new one, functional, which uses the useSelector() hook, and an older one, which is class based, but needs to use this sasme store to dispatch an action.
To do this, I import the store and fire
store.dispatch({type: 'user/validate', payload: newUser});
from the class component. I receive no errors, yet nothing happens at all.
I tracked my input from DevTools' Redux plugin, and I can see the state does not change, so I assume my manual call to dispatch is somehow wrong.
What I expect to happen is for the state to update, which would trigger a re-render of the component that uses useSelector