I have an event app with a signup form with a list of checkboxes that contain reasons as to why the user wants to sign up for events. On our events page we have a similar signup form, however when signing up on the events page it’s already implied they want to attend events, so I want to always pass the “I want to attend events” checkbox value when they signup. Currently, I have it set to it’s checked every by default but I’m confused on how to also send that value by default, storing these values in ‘reasons’. When submit is clicked, nothing populates for reasons but I always need at least one reason each time
const [reasons, setReasons] = useState([])
what happens when a checkbox is checked
const onReasonChange = event => {
// Remove the reason if already selected
if (reasons.includes(event.target.value)) {
setReasons(reasons.filter(reason => reason !== event.target.value))
return
}
// Add the reason
setReasons([...reasons, event.target.value])
}
the checkbox i’m trying to get to always send the value of
<input
id="attend"
type="checkbox"
value="I want to attend events"
onChange={onReasonChange}
checked={reasons.includes("I want to attend events"), 'checked'}
/>