Created
January 17, 2023 23:28
-
-
Save ChristianOConnor/3b680ade37af2e6fcfed6917e4885c74 to your computer and use it in GitHub Desktop.
ToggleSwitch.tsx for https://stackoverflow.com/questions/75153066/how-do-i-get-the-value-of-a-usestate-hook-from-an-imported-component-in-a-react
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, { Dispatch, SetStateAction } from "react"; | |
import "./ToggleSwitch.css"; | |
function ToggleSwitch({ toggledVal, setToggled } : { toggledVal: boolean, setToggled: Dispatch<SetStateAction<boolean>> }) { | |
const onToggle = () => setToggled(!toggledVal); | |
return ( | |
<label className="toggle-switch"> | |
<input type="checkbox" checked={toggledVal} onChange={onToggle} /> | |
<span className="switch" /> | |
</label> | |
); | |
} | |
export default ToggleSwitch; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment