Created
August 6, 2021 09:53
-
-
Save gtchakama/317c3b5d450dbcddbd20b6a327e73ca5 to your computer and use it in GitHub Desktop.
React useState ("Toggle")
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
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; | |
} |
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 "./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> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
React useState - Toggle
Blog Article