Last active
November 19, 2020 19:00
-
-
Save VihangaN/82c951f9d21ddc7b937c1a49498a0321 to your computer and use it in GitHub Desktop.
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
import React, { useState } from "react"; | |
export default function App() { | |
let [isOn, setOn] = useState(false); | |
const toggle = (e) => { | |
if (e.target.checked) { | |
setOn(true); | |
} else { | |
setOn(false); | |
} | |
}; | |
return ( | |
<> | |
<label className="slider"> | |
<input type="checkbox" onChange={toggle} /> | |
<div className="sort"></div> | |
</label> | |
<span>{isOn ? "ON" : "OFF"}</span> | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment