Files
personal-site/components/ThemeToggle.js
T
Jesse EgbosionuandClaude Opus 5.5 3bb0a5e4a9 feat: redesign site as a modern developer portfolio
- New home page: hero, stats, about, focus areas, stack, projects, contact
- Light/dark theme with system default and persisted toggle
- Content centralised in data/profile.js
- Restyle /rates to match; remove it from nav and projects
- Afriex: log a clear error now that its API requires a device id

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 21:19:22 +02:00

31 lines
737 B
JavaScript

import { useEffect, useState } from 'react';
import Icon from './Icon';
export default function ThemeToggle() {
const [theme, setTheme] = useState(null);
useEffect(() => {
setTheme(document.documentElement.dataset.theme || 'light');
}, []);
const toggle = () => {
const next = theme === 'dark' ? 'light' : 'dark';
document.documentElement.dataset.theme = next;
try {
localStorage.setItem('theme', next);
} catch (e) {}
setTheme(next);
};
return (
<button
type="button"
className="icon-button"
onClick={toggle}
aria-label={`Switch to ${theme === 'dark' ? 'light' : 'dark'} theme`}
>
<Icon name={theme === 'dark' ? 'sun' : 'moon'} />
</button>
);
}