From 14b1e44f045ed2424874dbf06187bc998a792972 Mon Sep 17 00:00:00 2001
From: Gildas Garcia <1122076+djhi@users.noreply.github.com>
Date: Mon, 18 Jan 2021 11:53:43 +0100
Subject: [PATCH] Ensure Redux Store Is Not Recreated when Admin Update
---
.../ra-core/src/core/CoreAdminContext.tsx | 30 +++++++++----------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/packages/ra-core/src/core/CoreAdminContext.tsx b/packages/ra-core/src/core/CoreAdminContext.tsx
index a8fe97479e4..ef52bbf4d5b 100644
--- a/packages/ra-core/src/core/CoreAdminContext.tsx
+++ b/packages/ra-core/src/core/CoreAdminContext.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { FunctionComponent, ComponentType, useContext } from 'react';
+import { FunctionComponent, ComponentType, useContext, useState } from 'react';
import { Provider, ReactReduxContext } from 'react-redux';
import { History } from 'history';
import { createHashHistory } from 'history';
@@ -87,6 +87,19 @@ React-admin requires a valid dataProvider function to work.`);
);
};
+ const [store] = useState(() =>
+ !reduxIsAlreadyInitialized
+ ? createAdminStore({
+ authProvider: finalAuthProvider,
+ customReducers,
+ customSagas,
+ dataProvider: finalDataProvider,
+ initialState,
+ history: finalHistory,
+ })
+ : undefined
+ );
+
if (reduxIsAlreadyInitialized) {
if (!history) {
throw new Error(`Missing history prop.
@@ -95,20 +108,7 @@ React-admin uses this history for its own ConnectedRouter.`);
}
return renderCore();
} else {
- return (
-
- {renderCore()}
-
- );
+ return {renderCore()};
}
};