Closed xcarpentier closed 5 years ago
looks correct, possibly autorehydrate is not being applied
@rt2zz @xcarpentier I've been struggling with the same issue. If I understand it correctly when we are using redux-persist-immutable and redux-persist in createPersistor.js we are having those variables
var stateIterator = config._stateIterator || defaultStateIterator;
var stateGetter = config._stateGetter || defaultStateGetter;
var stateSetter = config._stateSetter || defaultStateSetter;
overriden from config:
function _stateIterator(state, callback) {
return state.forEach(callback);
}
function _stateGetter(state, key) {
return state.get(key);
}
function _stateSetter(state, key, value) {
return state.set(key, value);
}
But the thing is stateIterator, stateGetter and stateSetter are used for current state which is got by store.getState() and since I'm using combineReducers I get plain object instead of immutableJs one.
Here is a note from redux tutorial
The resulting reducer calls every child reducer, and gathers their results into a single state object. The shape of the state object matches the keys of the passed reducers. Consequently, the state object will look like this:
{ reducer1: ... reducer2: ... }
So I believe those stateIterator, stateGetter and stateSetter should be used on inner ImmutableJs objects but not on the object returned by store.getState().
I got exactly same error here. Is there any workaround to bypass this error?
Using this code, I was getting the 'state.forEach' is not a function error. Now, I seem to get 'state.has' is not a function error. I assume these errors are related to having immutablejs just on substate instead of the full state. I verified that using a single state works. What is the magic to get multiple substates to work? Thanks.
const combinedReducers = combineReducers(
{
subStateA: stateAReducer,
subStateB: stateBReducer
}
);
// combine initial state here; or set as default value on reducer which will be loaded when the reducer is
const combinedInitialState = {
subStateA: fromJS(subStateBInitialData),
subStateB: fromJS(subStateBInitialData)
};
const store = createStore(combinedReducers, combinedInitialState, composeEnhancers(middleware, autoRehydrate()));
persistStore(store);
Same error here.
The same error , anyone have a workaround for this issue ?
Any update?
I got the error too, and I resolved it by using:
// Array.prototype.forEach.call(state, (key: PropertyKey) => {
[].forEach.call(state, (key: PropertyKey) => {
// do something...
});
or this:
Object.keys(state).map((key: PropertyKey) => {
// do something...
});
I think it is because state is an Array-like object, maybe.. :)
@xcarpentier any idea what @ghost meant by the resolution that he came up with... I can't see any code even resembling this in any parts of Immer / Redux-persist-immutable, etc... Where did he place this fix?
Hello, I have this error:
My store is configure like that:
My reducer like that:
Do you have any idea about this issue ?