Skip to content

[FE-28] Build Dark Mode Theme Toggle with next-themes and hydration guard #1007

@devwums

Description

@devwums

Problem

The dark mode toggle does not persist across page navigations or browser sessions. The selected theme resets to light mode on every page load.

Proposed Solution

Create frontend/cntr/ThemeToggle/ThemeToggle.tsx. Uses next-themes (already installed) useTheme() hook. Renders a button toggling between Sun and Moon icons from lucide-react. Guards against hydration mismatch by rendering nothing until mounted is true. All implementation must live inside frontend/cntr/.

Acceptance Criteria

  • File at frontend/cntr/ThemeToggle/ThemeToggle.tsx
  • Uses next-themes useTheme hook — no manual localStorage reads
  • Shows Sun icon in dark mode, Moon icon in light mode
  • Renders null (or a placeholder) until mounted is true to prevent hydration mismatch
  • Test in frontend/cntr/ThemeToggle/ThemeToggle.test.tsx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions