Skip to content

Instantly share code, notes, and snippets.

@djD-REK
Last active September 10, 2019 02:18
Show Gist options
  • Save djD-REK/cae19da34450316983f548a6534ea2aa to your computer and use it in GitHub Desktop.
Save djD-REK/cae19da34450316983f548a6534ea2aa to your computer and use it in GitHub Desktop.
Create Dark Mode for React with use-dark-mode
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