Created
August 18, 2023 13:18
-
-
Save paulodutra/8edb1ff5157f3b86b30aecb3daa228eb to your computer and use it in GitHub Desktop.
An example of checkbox component using the inline onChange function 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); | |
return ( | |
<label style={{ | |
padding: "1rem", | |
border: value ? "2px solid #8D2" : "2px solid #F70" | |
}}> | |
<input | |
type='checkbox' | |
checked={value} | |
onChange={({currentTarget}) => setValue(currentTarget.checked)} | |
/> | |
{label} | |
</label> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment