-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
Here's a very basic, valid, store enhancer that essentially wraps the store's original getState
in a new getState
function:
const basicStoreEnhancer = (createStore) => (...args) => {
const store = createStore(...args);
return {
...store,
getState: () => store.getState(),
};
};
When used with Redux's compose
, this enhancer works perfectly with no impact at all. However, when used within a composeWithDevTools
, it results in a RangeError: Maximum call stack size exceeded
.
This is because of this line, which mutates the store causing our getState
call to become infinitely recursive:
stores[instanceId].getState = store.getState; |
It's possible to work around the issue like this:
const basicStoreEnhancer = (createStore) => (...args) => {
const store = createStore(...args);
const originalGetState = store.getState;
return {
...store,
getState: () => originalGetState(),
};
};
Metadata
Metadata
Assignees
Labels
No labels