chore(web): document set-state-in-effect on ThemeToggle localStorage read (#90) #93
1 changed files with 5 additions and 0 deletions
|
|
@ -12,6 +12,11 @@ export function ThemeToggle() {
|
|||
|
||||
useEffect(() => {
|
||||
const stored = localStorage.getItem("sl-theme") as Theme | null;
|
||||
// localStorage is unavailable during SSR, so the stored theme can only be
|
||||
// read post-mount. ThemeScript already applies the `dark` class before
|
||||
// hydration (no page FOUC); only the toggle icon corrects on mount. The
|
||||
// rule is a false positive for this hydration-from-localStorage read.
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
if (stored) setTheme(stored);
|
||||
}, []);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue