Skip to content

Commit

Permalink
only get initial mode once
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Mar 8, 2021
1 parent 4f5358b commit de85ee5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Tool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const DarkMode = ({ api }: DarkModeProps) => {
const { current: defaultMode, stylePreview, ...params } = darkModeParams

// Save custom themes on init
const initialMode = React.useRef(store(params).current);
const initialMode = React.useMemo(() => store(params).current, [params]);

/** Set the theme in storybook, update the local state, and emit an event */
const setMode = React.useCallback(
Expand Down Expand Up @@ -190,7 +190,7 @@ export const DarkMode = ({ api }: DarkModeProps) => {
// need the effect to run whenever defaultMode is updated
React.useEffect(() => {
// If a users has set the mode this is respected
if (initialMode.current) {
if (initialMode) {
return;
}

Expand All @@ -199,7 +199,7 @@ export const DarkMode = ({ api }: DarkModeProps) => {
} else if (prefersDark.matches) {
updateMode('dark');
}
}, [defaultMode, updateMode]);
}, [defaultMode, updateMode, initialMode]);

return (
<IconButton
Expand Down

0 comments on commit de85ee5

Please sign in to comment.