Last active
August 12, 2019 19:32
-
-
Save djD-REK/3d2bc7412dcd83db8d240367804c928c to your computer and use it in GitHub Desktop.
Used in the Medium article: Dark Mode for ANY React App 2019: Part 1 of a Series on Day/Night Toggles
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, { 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 darkMode = useDarkMode(false); | |
const getDayNightAsString = () => { | |
if (darkMode.value) return "π Night"; | |
else return "βοΈ Day"; | |
}; | |
const emojify = () => { | |
return ( | |
<h1> | |
<span role="img" aria-label="Decorative Emojis"> | |
βοΈβ€οΈβπββ±β·βοΈβοΈ | |
</span> | |
</h1> | |
); | |
}; | |
return ( | |
<div className="App"> | |
<div className="container"> | |
{emojify()} | |
<h2>{getDayNightAsString()} Mode π₯³</h2> | |
<button onClick={darkMode.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
I would destructure here:
Also, instead of calling a function, just create a string const.
then in your render: