() => { const [checkedValues, setCheckedValues] = React.useState({ checkbox: {}, switch: {}, radio: '1', }); const handleChange = (type, { target }) => { const { value, checked } = target; setCheckedValues(prevState => { const newState = { ...prevState }; if (newState[type] === undefined) { newState[type] = {}; } if (type === 'radio') { newState[type] = value; } else { newState[type][value] = checked; } return newState; }); }; const isChecked = (type, value) => type === 'radio' ? checkedValues[type] === value : !!checkedValues[type][value]; return ( <Stack> {['1', '2', '3'].map(id => ( <Choice key={id} id={'choice' + id} name="name" info={props.info} title={props.title + ' ' + id} message={props.message} type={props.type} checked={isChecked(props.type, id)} value={id} error={props.error} disabled={props.disabled} onChange={e => handleChange(props.type, e)} > Choice Body Text </Choice> ))} </Stack> ); }