Code RoomlocalStorage hydration mismatch
HardPrep Room Coding #1824

localStorage hydration mismatch

Code reviewStorage & CDNSenior–Staff~24 min

Review this React TypeScript component (Next.js App Router).

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 24 min
Mark a line and say what kind of problem it is.0 findings
1function ThemeToggle() {
2 const [theme, setTheme] = useState(
3 typeof window !== 'undefined' ? localStorage.getItem('theme') ?? 'light' : 'light'
4 );
5 
6 return (
7 <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')} className={theme}>
8 Toggle theme
9 </button>
10 );
11}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.