useThemeSwitcher
Location: src/hooks/useThemeSwitcher.js
Overview
A development/preference hook for switching between experimental visual themes. Applies a CSS class to the document root element (<html>) and persists the user's choice to localStorage under the key commonplace-experimental-theme.
Available themes: default, neon, forest, circus. Each maps to a corresponding CSS class (theme-default, theme-neon, etc.).
Signature
function useThemeSwitcher(): {
currentTheme: string,
setTheme: (theme: string) => void,
cycleTheme: () => void,
availableThemes: string[]
}
Parameters
None.
Return Value
| Property | Type | Description |
|---|---|---|
currentTheme | string | The currently active theme key (e.g. "default", "neon"). |
setTheme | (theme: string) => void | Set a specific theme by key. Updates the DOM class and persists to localStorage. |
cycleTheme | () => void | Cycle to the next theme in the list. Wraps around from the last theme back to the first. |
availableThemes | string[] | Array of all available theme keys: ["default", "neon", "forest", "circus"]. |
Usage
function ThemeToggle() {
const { currentTheme, cycleTheme, availableThemes } = useThemeSwitcher();
return (
<button onClick={cycleTheme}>
Theme: {currentTheme}
</button>
);
}
Setting a specific theme
function ThemeSelector() {
const { currentTheme, setTheme, availableThemes } = useThemeSwitcher();
return (
<select value={currentTheme} onChange={(e) => setTheme(e.target.value)}>
{availableThemes.map(theme => (
<option key={theme} value={theme}>{theme}</option>
))}
</select>
);
}
Last updated: 2026-02-07