Skip to content

Instantly share code, notes, and snippets.

@paulodutra
Created August 18, 2023 13:18
Show Gist options
  • Save paulodutra/8edb1ff5157f3b86b30aecb3daa228eb to your computer and use it in GitHub Desktop.
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
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