Skip to content

Instantly share code, notes, and snippets.

@gtchakama
Created August 6, 2021 09:53
Show Gist options
  • Save gtchakama/317c3b5d450dbcddbd20b6a327e73ca5 to your computer and use it in GitHub Desktop.
Save gtchakama/317c3b5d450dbcddbd20b6a327e73ca5 to your computer and use it in GitHub Desktop.
React useState ("Toggle")
main{
display: flex;
min-height: 100vh;
justify-content: center;
flex-direction: column;
background-color: #282c34;
padding: 10px 500px;
}
div {
text-align: center;
align-items: center;
font-size: calc(10px + 2vmin);
color: white;
}
button {
padding: 10px;
font-size: 18px;
cursor: pointer;
width: 100%;
}
h1{
font-size: 9em;
margin: 15px;
}
import React, { useState } from "react";
import "./App.css";
export default function App() {
const [showEmoji, setShowemoji] = useState("");
const emoji = "🤒";
const emoji2 = "👨‍⚕️";
return (
<main>
<div>
<h2>useState ( ) </h2>
<h1> {showEmoji ? emoji : emoji2}</h1>{" "}
<button onClick={(e) => setShowemoji(!showEmoji)}>Toggle</button>
</div>
</main>
);
}
@gtchakama
Copy link
Author

React useState - Toggle

Blog Article

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