Skip to content

Commit

Permalink
Fix issue with theme initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Graeme Houston committed Aug 27, 2024
1 parent 9a8a5a3 commit a6538b1
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/context/ThemeContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createContext, useContext, useEffect, useState } from "react";
import React, { createContext, useContext, useState } from "react";
import {
BaseThemeObject,
ThemeContextType,
Expand All @@ -25,7 +25,6 @@ const createTheme = (baseTheme: Partial<BaseThemeObject> = {}): ThemeObject => {
surfaceText,
surface,
} = mergedTheme;

return {
...mergedTheme,
sizes,
Expand All @@ -44,17 +43,18 @@ const ThemeProvider: React.FC<ThemeProviderProps> = ({
theme: providedTheme,
}) => {
const [theme, setTheme] = useState<ThemeObject>(() =>
createTheme(providedTheme)
createTheme(providedTheme || {})
);

useEffect(() => {
if (providedTheme) {
setTheme(createTheme(providedTheme));
}
}, [providedTheme]);
const contextValue: ThemeContextType = {
theme,
setTheme: (newTheme: Partial<BaseThemeObject>) => {
setTheme(createTheme(newTheme));
},
};

return (
<ThemeContext.Provider value={{ theme, setTheme }}>
<ThemeContext.Provider value={contextValue}>
{children}
</ThemeContext.Provider>
);
Expand Down

0 comments on commit a6538b1

Please sign in to comment.