({onChange})
| 5 | export default Theme; |
| 6 | |
| 7 | export function ThemeToggleButton({onChange}) { |
| 8 | let theme = useContext(Theme); |
| 9 | let [targetTheme, setTargetTheme] = useState(theme); |
| 10 | function toggleTheme() { |
| 11 | let newTheme = theme === 'light' ? 'dark' : 'light'; |
| 12 | // High pri, responsive update. |
| 13 | setTargetTheme(newTheme); |
| 14 | // Perform the actual theme change in a separate update. |
| 15 | setTimeout(() => onChange(newTheme), 0); |
| 16 | } |
| 17 | if (targetTheme !== theme) { |
| 18 | return 'Switching to ' + targetTheme + '...'; |
| 19 | } |
| 20 | return ( |
| 21 | <a className="link" onClick={toggleTheme}> |
| 22 | Switch to {theme === 'light' ? 'Dark' : 'Light'} theme |
| 23 | </a> |
| 24 | ); |
| 25 | } |
nothing calls this directly
no test coverage detected