Skip to content

Instantly share code, notes, and snippets.

@VihangaN
Last active November 19, 2020 19:00
Show Gist options
  • Save VihangaN/82c951f9d21ddc7b937c1a49498a0321 to your computer and use it in GitHub Desktop.
Save VihangaN/82c951f9d21ddc7b937c1a49498a0321 to your computer and use it in GitHub Desktop.
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