Skip to content

Instantly share code, notes, and snippets.

@djD-REK
Last active August 12, 2019 19:32
Show Gist options
  • Save djD-REK/3d2bc7412dcd83db8d240367804c928c to your computer and use it in GitHub Desktop.
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
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);
@djD-REK
Copy link
Author

djD-REK commented Aug 12, 2019

Thanks @donavon that was very helpful, I'm updating it now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment