Skip to content

Commit 966a60c

Browse files
authored
Merge pull request #145 from scalprum/memoize-scaprum-provider-value
fix(react): memoize provider value
2 parents baa5762 + a7b95eb commit 966a60c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

packages/react-core/src/scalprum-provider.tsx

+13-8
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,20 @@ export function ScalprumProvider<T extends Record<string, any> = Record<string,
7272
// @ts-ignore
7373
}, [props.api, props.config, props.scalprum]);
7474

75+
const value = useMemo(
76+
() => ({
77+
config: state.appsConfig,
78+
api: state.api,
79+
initialized: true,
80+
pluginStore: state.pluginStore,
81+
}),
82+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
83+
// @ts-ignore
84+
[props.api, props.config, props.scalprum, state],
85+
);
86+
7587
return (
76-
<ScalprumContext.Provider
77-
value={{
78-
config: state.appsConfig,
79-
api: state.api,
80-
initialized: true,
81-
pluginStore: state.pluginStore,
82-
}}
83-
>
88+
<ScalprumContext.Provider value={value}>
8489
<PluginStoreProvider store={state.pluginStore}>{props.children}</PluginStoreProvider>
8590
</ScalprumContext.Provider>
8691
);

0 commit comments

Comments
 (0)