Skip to content

Instantly share code, notes, and snippets.

@paulodutra
Created August 18, 2023 13:13
Show Gist options
  • Save paulodutra/bfe3339881afcec2e5cb51f5f3f6c78c to your computer and use it in GitHub Desktop.
Save paulodutra/bfe3339881afcec2e5cb51f5f3f6c78c to your computer and use it in GitHub Desktop.
An example of checkbox component using the React.ChangeEventHandle to set value
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