Skip to content

Commit

Permalink
check if isClient for other parts of component
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadgaz committed Oct 2, 2024
1 parent 19be82d commit a413b80
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion components/molecules/client/color-mode-picker/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const ColorModePickerWithoutCookies: React.FC = () => {
setTheme(localStorage.theme);
}, []);
React.useEffect(() => {
if (!isClient) {
return;
}
if (theme) {
localStorage.theme = theme;
} else {
Expand All @@ -37,11 +40,14 @@ const ColorModePickerWithoutCookies: React.FC = () => {
document.documentElement.classList.remove('dark');
setCookie('theme', 'light', { path: '/' });
}
}, [theme, setCookie]);
}, [theme, isClient, setCookie]);
function handleChange(e: React.ChangeEvent<HTMLSelectElement>) {
const theme = e.target.value;
setTheme(theme);
}
if (!isClient) {
return null;
}
return (
<Select defaultValue={theme ?? ''} onChange={handleChange}>
<option value="">System</option>
Expand Down

0 comments on commit a413b80

Please sign in to comment.