How can I inject reducer before render
Beace opened this issue · comments
Is your feature request related to a problem? Please describe.
inject reducer namespace before render
just return state.home
what is the issue ? I couldnt understand. But to explain that line of code, state
can return undefined and state.home
is causing a crash in that case. So if there is no state shouldn't we use initalState
?
If I do not use reselect, I have to do this in mapStateToProps
.
const mapStateToProps = (state) => {
return {
data: state.home ? state.home.data : initialState.data,
userinfo: state.home ? state.home.userinfo : initialState.userinfo,
...
};
};
Sorry for that, Is there a simple way to get the initialState
directly?
Still unclear. If you dont use reselect then you have to destruct state into your objects of course.
why not like this ?
const mapStateToProps = (state) => {
const homeState = state ? state.home || initialState : initialState;
return {
data: homeState.data,
userinfo: homeState.userinfo,
...
};
};
I already know the reason for this problem. Thank you for your reply. I just wonder why render method was executed twice after injecting reducer.Is it because there is no initialization?
const withReducer = injectReducer({ key: 'certificate', reducer: reducer });
const withSaga = injectSaga({ key: 'certificate', saga: saga });
hmm which of the things you said about is problem. Can you explain very simply. Because so far you asked
- How can I inject reducer after render
- Is there a simple way to get the initialState directly?
- Not using reselect
all these are seperate things. I dont understand what the problem is ? or is this a question? When you run the boilerplate code render
isn't executed twice. So i have no idea how to reproduce. Or what to reproduce.
I'm sorry to trouble you, but I refer to the latest react-boilerplate and react-boilerplate-typescript. I put these two together, partly dependent on versions that are inconsistent. It may be my personal problem. I'll debug it again.Thank you again for your reply.
Ohh react-boilerplate relased a new version a week ago 4.0.0. Mine is still 3.7.0. I'm gonna update repo too soon. So the latest version are not the same.
When I find the problem, I may be able to contribute a pr.
I found the problem and it was a problem with the react-boilerplate. I cloned the latest react-boilerplate directly and found that mapStateToProps did indeed execute twice.