This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
withReducer should initialize state using default argument #247
Comments
I see the problem, here initial state should be initialized like in redux with action of type https://github.com/reactjs/redux/blob/master/src/createStore.js#L11 So lines above becomes state = {
stateValue: reducer(
typeof initialState === 'function'
? initialState(this.props)
: initialState,
{ type: ActionTypes.INIT }
)
}; |
Do you want to provide a PR? |
If the basic idea is acceptable, I do. |
Yes, acceptable. |
FYI, I believe this was done by design. @acdlite has stated several times that if he could co-design redux again, he would not allow reducers to specify an initial state. I assume the asymmetry of this library with respect to redux is due to this belief. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Usually, in Redux reducers can provide initial state from themselves, using default argument value
This reducer works within redux store but doesn't work with recompose as expected.
Is there any chance to fix this? For example, call reducer with arbitrary action to get the initial state only when the last argument (initial state) for
withReducer
is not provided. It will not be breaking for current users, but it will increase reusability of reducers, so you can change them from in-place with recompose to global with redux and the other way round.The text was updated successfully, but these errors were encountered: