From c54714745507ae3101be4a5cc799000007bbce33 Mon Sep 17 00:00:00 2001 From: Peter Kulko <93188219+PKulkoRaccoonGang@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:11:37 +0300 Subject: [PATCH] docs: fix theme switcher on the Colors page (#2628) --- www/src/pages/foundations/colors.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/www/src/pages/foundations/colors.tsx b/www/src/pages/foundations/colors.tsx index 695243d62d..0ff51b0284 100644 --- a/www/src/pages/foundations/colors.tsx +++ b/www/src/pages/foundations/colors.tsx @@ -1,4 +1,4 @@ -import React, { useContext } from 'react'; +import React, { useState, useEffect, useContext } from 'react'; import { graphql } from 'gatsby'; import PropTypes from 'prop-types'; import classNames from 'classnames'; @@ -122,7 +122,16 @@ export interface IColorsPage { // eslint-disable-next-line react/prop-types export default function ColorsPage({ data }: IColorsPage) { const { settings } = useContext(SettingsContext); - const styles = typeof window !== 'undefined' ? getComputedStyle(document.body) : null; + const [styles, setStyles] = useState(null); + + useEffect(() => { + setTimeout(() => { + if (typeof window !== 'undefined') { + const newStyles = getComputedStyle(document.body); + setStyles(newStyles); + } + }, 500); + }, [settings.theme]); parseColors(data.allCssUtilityClasses.nodes); // eslint-disable-line react/prop-types