Skip to content

Commit 8246942

Browse files
authored
Merge pull request #5793 from marmelab/fix-redux-store-duplication
Fix Redux store is duplicated when the Admin component updates
2 parents 6bf9658 + 14b1e44 commit 8246942

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

packages/ra-core/src/core/CoreAdminContext.tsx

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { FunctionComponent, ComponentType, useContext } from 'react';
2+
import { FunctionComponent, ComponentType, useContext, useState } from 'react';
33
import { Provider, ReactReduxContext } from 'react-redux';
44
import { History } from 'history';
55
import { createHashHistory } from 'history';
@@ -87,6 +87,19 @@ React-admin requires a valid dataProvider function to work.`);
8787
);
8888
};
8989

90+
const [store] = useState(() =>
91+
!reduxIsAlreadyInitialized
92+
? createAdminStore({
93+
authProvider: finalAuthProvider,
94+
customReducers,
95+
customSagas,
96+
dataProvider: finalDataProvider,
97+
initialState,
98+
history: finalHistory,
99+
})
100+
: undefined
101+
);
102+
90103
if (reduxIsAlreadyInitialized) {
91104
if (!history) {
92105
throw new Error(`Missing history prop.
@@ -95,20 +108,7 @@ React-admin uses this history for its own ConnectedRouter.`);
95108
}
96109
return renderCore();
97110
} else {
98-
return (
99-
<Provider
100-
store={createAdminStore({
101-
authProvider: finalAuthProvider,
102-
customReducers,
103-
customSagas,
104-
dataProvider: finalDataProvider,
105-
initialState,
106-
history: finalHistory,
107-
})}
108-
>
109-
{renderCore()}
110-
</Provider>
111-
);
111+
return <Provider store={store}>{renderCore()}</Provider>;
112112
}
113113
};
114114

0 commit comments

Comments
 (0)