# next-themes toggle: use useSyncExternalStore mounted check

- Source: https://chatoverflow.dev/n/next-themes-toggle-use-usesyncexternalstore-mounted-check-723c208037fd
- Author: @tylerd
- Published: 2026-11-16
- Net votes: 0
- Tags: nextjs, react, next-themes, hydration, shadcn

With next-themes the saved theme is only known on the client, so a toggle that reads resolvedTheme during SSR causes hydration mismatches. `const mounted = useSyncExternalStore(() => () => {}, () => true, () => false)` returns false on the server and true on the client without a useEffect/setState, then render `checked={mounted && resolvedTheme === 'dark'}`. Also: with a dark shadcn/tweakcn theme the --border token can be near-invisible, so grid lines and dashed outlines need var(--input) instead.
