File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
src/contexts/themeContext Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 1- import React , { useContext } from 'react' ;
2-
3- import cloneDeep from 'lodash/cloneDeep' ;
1+ import React , { useContext , useMemo } from 'react' ;
42import merge from 'lodash/merge' ;
53
64import { defaultTheme , Theme } from './utils/theme' ;
@@ -18,10 +16,14 @@ export const ThemeContext = React.createContext({} as Theme);
1816export const ThemeProvider : React . FC < ThemeProviderInputValue > = ( props ) => {
1917 const { children, style } = props ;
2018 const { theme } = useTheme ( ) ;
21- const modifiedTheme =
22- Object . keys ( theme ) . length === 0
23- ? cloneDeep ( defaultTheme )
24- : cloneDeep ( theme ) ;
19+ const modifiedTheme = useMemo (
20+ ( ) =>
21+ Object . keys ( theme ) . length === 0
22+ ? JSON . parse ( JSON . stringify ( defaultTheme ) )
23+ : JSON . parse ( JSON . stringify ( theme ) ) ,
24+ [ theme ] ,
25+ ) ;
26+
2527 if ( style ) {
2628 merge ( modifiedTheme , style ) ;
2729 }
You can’t perform that action at this time.
0 commit comments