Created
December 20, 2020 18:39
-
-
Save zHaytam/44a55bb3ce36610b697e469bdbc6cff7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useContext } from 'react'; | |
import ThemeContext from './ThemeContext'; | |
const ThemeToggler = () => { | |
const { theme, setTheme } = useContext(ThemeContext); | |
return ( | |
<div | |
style={{ cursor: 'pointer' }} | |
title="switch theme" | |
onClick={() => { | |
setTheme(theme === 'light' ? 'dark' : 'light'); | |
}} | |
> | |
{theme === 'light' ? '🌙' : '☀️'} | |
</div> | |
); | |
}; | |
export default ThemeToggler; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment