Created
January 7, 2024 13:52
-
-
Save nknighta/5641fa7dbe022376cc7de68b4aeaa5cf to your computer and use it in GitHub Desktop.
React Toggle Button
This file contains 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
const WebToggle = () => { | |
const [toggle, setToggle] = useState<boolean>(false); | |
toggle ? '#000' : '#fff'; | |
return ( | |
<div> | |
<h1>WebToggle</h1> | |
<button onClick={() => { | |
setToggle(!toggle); | |
}} | |
style={{ | |
background: toggle ? '#000' : '#fff', | |
color: toggle ? '#fff' : '#000', | |
border: '1px solid #000', | |
borderRadius: '5px', | |
padding: '5px' | |
}} | |
> | |
Toggle {toggle ? 'ON' : 'OFF'} | |
</button> | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment