mercredi 23 mars 2022

Why does the react hooks checkbox give an incorrect value?

This checkbox is consistent in displaying the wrong value of 'checked'

 <input type='checkbox'
 name='isCheckeD' 
 id='isChecked'
 checked={formData.isCheckeD}
 onChange={handleChecked}
 />

the function is

function handleChecked(e) {
    const {name, checked} = e.target 
    formDataSet( cB => {
            return {...cB, [name]: checked}
        }) 
}

and the state is:

const [formData, formDataSet] = useState(
    {
     isCheckeD: false    
    }
)

Any ideas?




Aucun commentaire:

Enregistrer un commentaire