Skip to content

Instantly share code, notes, and snippets.

@zHaytam
Created December 20, 2020 18:39
Show Gist options
  • Save zHaytam/44a55bb3ce36610b697e469bdbc6cff7 to your computer and use it in GitHub Desktop.
Save zHaytam/44a55bb3ce36610b697e469bdbc6cff7 to your computer and use it in GitHub Desktop.
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