Last active
September 10, 2019 02:18
-
-
Save djD-REK/cae19da34450316983f548a6534ea2aa to your computer and use it in GitHub Desktop.
Create Dark Mode for React with use-dark-mode
This file contains 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, { useState } from "react"; | |
import ReactDOM from "react-dom"; | |
import useDarkMode from "use-dark-mode"; // Don't forget to import the NPM package use-dark-mode | |
import "./styles.scss"; | |
function App() { | |
const { value, toggle } = useDarkMode(false); | |
const dayNightAsString = value ? "🌕 Night": "☀️ Day"; | |
const emojify = () => { | |
return ( | |
<h1> | |
<span role="img" aria-label="Decorative Emojis"> | |
⭐️❤️☕🍍☄⛱⛷☀️☘️ | |
</span> | |
</h1> | |
); | |
}; | |
return ( | |
<div className="App"> | |
<div className="container"> | |
{emojify()} | |
<h2>{dayNightAsString} Mode 🥳</h2> | |
<button onClick={toggle}> | |
<h3>Toggle Day / Night</h3> | |
</button> | |
{emojify()} | |
</div> | |
</div> | |
); | |
} | |
const rootElement = document.getElementById("root"); | |
ReactDOM.render(<App />, rootElement); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment