Created
August 18, 2023 13:13
-
-
Save paulodutra/bfe3339881afcec2e5cb51f5f3f6c78c to your computer and use it in GitHub Desktop.
An example of checkbox component using the React.ChangeEventHandle to set value
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 from 'react' | |
export const Checkbox = ({ label} : {label: string}) => { | |
const [value, setValue] = React.useState(false); | |
const handleChange: React.ChangeEventHandler<HTMLInputElement> = (event) => { | |
setValue(event.currentTarget.checked) | |
} | |
return ( | |
<label style={{ | |
padding: "1rem", | |
border: value ? "2px solid #8D2" : "2px solid #F70" | |
}}> | |
<input type='checkbox' checked={value} onChange={handleChange} /> | |
{label} | |
</label> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment