Premium
React Theme Toggle with Persisted Light/Dark Mode
Add a global light/dark theme toggle using React Context. The selected theme should be stored in localStorage and restored when the page reloads. React focus: use Context to persist theme in localStorage and sync the DOM attribute. Framework focus: React hooks (useState/useEffect), JSX event handling,…
- Render a main page layout with a simple content card and a…
- Support two themes: "light" and "dark".
What you’ll build / What this tests
This premium react coding focuses on React Theme Toggle with Persisted Light/Dark Mode. You’ll apply react and context thinking with intermediate level constraints. The prompt emphasizes Add a global light/dark theme toggle using React Context. The selected theme should be stored in….
Learning goals
- Translate the prompt into a clear react API signature and return shape.
- Apply react, context, state techniques to implement react theme toggle with persisted light/dark mode.
- Handle intermediate edge cases without sacrificing readability.
- Reason about time/space complexity and trade-offs in react.
Key decisions to discuss
- Define the exact input/output contract before coding.
- Prioritize predictable edge-case handling over micro-optimizations.
Evaluation rubric
- Correctness: covers required behaviors and edge cases.
- Clarity: readable structure and predictable control flow.
- Complexity: avoids unnecessary work for large inputs.
- API discipline: no mutation of inputs; returns expected shape.
- Testability: solution is easy to unit test.
Constraints / Requirements
- Render a main page layout with a simple content card and a theme toggle control in the top-right…
- Support two themes: "light" and "dark".
- Store the current theme in a React Context provider (global-ish state).
- Persist the selected theme in localStorage under a stable key.
- On initial load, read the theme from localStorage and apply it before the user interacts.
- Apply the theme at the document level by setting data-theme on , so the existing CSS can react…
- You only need to edit React/TypeScript files: /src/theme.tsx and /src/App.tsx. The CSS in /src/App.css is already wired to…
- By default, the app starts in light mode if there is no previous theme stored.
- If the user toggles to dark mode, the page background, text, and card colors change.
- Reloading the page keeps the user’s last theme selection (light or dark).
Mini snippet (usage only)
// Example usage
const input = /* react theme toggle with persisted light/dark mode input */;
const result = solve(input);
console.log(result);
// Edge case check
const empty = input ?? null;
const fallback = solve(input);
console.log(fallback);
// Expected: describe output shape, not the implementation
// (no solution code in preview)Common pitfalls
- Mutating inputs instead of returning a new value.
- Skipping edge cases like empty input, duplicates, or nulls.
- Overlooking time complexity for large inputs.
Related questions
Upgrade to FrontendAtlas Premium to unlock this challenge. Already upgraded? Sign in to continue.