Skip to content

Commit

Permalink
Merge pull request #145 from scalprum/memoize-scaprum-provider-value
Browse files Browse the repository at this point in the history
fix(react): memoize provider value
  • Loading branch information
Hyperkid123 authored Sep 24, 2024
2 parents baa5762 + a7b95eb commit 966a60c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/react-core/src/scalprum-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,20 @@ export function ScalprumProvider<T extends Record<string, any> = Record<string,
// @ts-ignore
}, [props.api, props.config, props.scalprum]);

const value = useMemo(
() => ({
config: state.appsConfig,
api: state.api,
initialized: true,
pluginStore: state.pluginStore,
}),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
[props.api, props.config, props.scalprum, state],
);

return (
<ScalprumContext.Provider
value={{
config: state.appsConfig,
api: state.api,
initialized: true,
pluginStore: state.pluginStore,
}}
>
<ScalprumContext.Provider value={value}>
<PluginStoreProvider store={state.pluginStore}>{props.children}</PluginStoreProvider>
</ScalprumContext.Provider>
);
Expand Down

0 comments on commit 966a60c

Please sign in to comment.