Closed ethax-ross closed 6 years ago
I found the/a solution - we should just export the initialState
from the reducer
and use it as the default value in the selector
as they do here:
In here:
@ross-freeagent It's an interesting find. I am away from my dev machine for three weeks now and I won't have access for two more weeks I guess. If you could create a PR, I'll be able to merge it though.
Selector solution will not update redux state, therefore redux devtools will not show that reducer initial state attached.
You could do
store.dispatch({ type: '@@REDUCER_INJECTED' });
(basically dispatching any action) after store.replaceReducer
, this will set initial state of the reducer to store state.
Thanks @ross-freeagent, @ruslansavenok and @piotr-roslaniec. The PR with the proposed solution is now merged.
If I don't include a reducer in
reducers.js
:And instead just inject it like so:
Then
reducer
never seems to set it'sinitialState
- I assume because they don't seem to receive the@@INIT
action that causes it to hit thedefault
in it'scase
statement:It looks like this is because it gets injected at
componentWillMount
, which is after@@INIT
... how do I get theinitialState
set so that it can be referenced atcomponentDidMount
?