Skip to content

Commit 9168465

Browse files
Moved theme merge to useMemo as well
1 parent c516314 commit 9168465

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/contexts/themeContext/ThemeContext.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@ export const ThemeContext = React.createContext({} as Theme);
1616
export const ThemeProvider: React.FC<ThemeProviderInputValue> = (props) => {
1717
const { children, style } = props;
1818
const { theme } = useTheme();
19-
const modifiedTheme = useMemo(
20-
() =>
19+
const modifiedTheme = useMemo(() => {
20+
const finalTheme =
2121
Object.keys(theme).length === 0
2222
? JSON.parse(JSON.stringify(defaultTheme))
23-
: JSON.parse(JSON.stringify(theme)),
24-
[theme],
25-
);
23+
: JSON.parse(JSON.stringify(theme));
24+
25+
if (style) {
26+
merge(finalTheme, style);
27+
}
2628

27-
if (style) {
28-
merge(modifiedTheme, style);
29-
}
29+
return finalTheme;
30+
}, [theme, style]);
3031

3132
return (
3233
<ThemeContext.Provider value={modifiedTheme}>

0 commit comments

Comments
 (0)