From a6538b111d5db47e790cb8cad7d078e564a15739 Mon Sep 17 00:00:00 2001 From: Graeme Houston Date: Tue, 27 Aug 2024 14:15:59 +0100 Subject: [PATCH] Fix issue with theme initialization --- lib/context/ThemeContext.tsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/context/ThemeContext.tsx b/lib/context/ThemeContext.tsx index 49d0c71..c4fa242 100644 --- a/lib/context/ThemeContext.tsx +++ b/lib/context/ThemeContext.tsx @@ -1,4 +1,4 @@ -import React, { createContext, useContext, useEffect, useState } from "react"; +import React, { createContext, useContext, useState } from "react"; import { BaseThemeObject, ThemeContextType, @@ -25,7 +25,6 @@ const createTheme = (baseTheme: Partial = {}): ThemeObject => { surfaceText, surface, } = mergedTheme; - return { ...mergedTheme, sizes, @@ -44,17 +43,18 @@ const ThemeProvider: React.FC = ({ theme: providedTheme, }) => { const [theme, setTheme] = useState(() => - createTheme(providedTheme) + createTheme(providedTheme || {}) ); - useEffect(() => { - if (providedTheme) { - setTheme(createTheme(providedTheme)); - } - }, [providedTheme]); + const contextValue: ThemeContextType = { + theme, + setTheme: (newTheme: Partial) => { + setTheme(createTheme(newTheme)); + }, + }; return ( - + {children} );