Skip to content

Commit

Permalink
Fix README hydration ThemeSwitcher example (#120)
Browse files Browse the repository at this point in the history
Using `resolvedTheme` will cause the select to show `light` or `dark` when `system` is selected rather than `system` as expected.

Co-authored-by: Paco <34928425+pacocoursey@users.noreply.github.com>
  • Loading branch information
Max Leiter and pacocoursey authored May 23, 2022
1 parent ee441b9 commit a85bb62
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ import { useTheme } from 'next-themes'

// Do NOT use this! It will throw a hydration mismatch error.
const ThemeSwitch = () => {
const { resolvedTheme, setTheme } = useTheme()
const { theme, setTheme } = useTheme()

return (
<select value={resolvedTheme} onChange={e => setTheme(e.target.value)}>
<select value={theme} onChange={e => setTheme(e.target.value)}>
<option value="system">System</option>
<option value="dark">Dark</option>
<option value="light">Light</option>
Expand All @@ -320,7 +320,7 @@ import { useTheme } from 'next-themes'

const ThemeSwitch = () => {
const [mounted, setMounted] = useState(false)
const { resolvedTheme, setTheme } = useTheme()
const { theme, setTheme } = useTheme()

// useEffect only runs on the client, so now we can safely show the UI
useEffect(() => {
Expand All @@ -332,7 +332,7 @@ const ThemeSwitch = () => {
}

return (
<select value={resolvedTheme} onChange={e => setTheme(e.target.value)}>
<select value={theme} onChange={e => setTheme(e.target.value)}>
<option value="system">System</option>
<option value="dark">Dark</option>
<option value="light">Light</option>
Expand Down

0 comments on commit a85bb62

Please sign in to comment.