mercredi 7 juillet 2021

Checked checkbox not fired first time when it unchecked after load the page react hook

I am trying to make the dark mode and light mode theme change via check box. when checkbox checked i set the dark mode and store value in cookies , on page load i set the checkbox checked according to cookies value and make the checkbox default checked. it working

But when i uncheck the checkbox it not fired anything and when check again it works. which mean first time change it not work. but for default unchecked checkbox is working fine.

Here is the checkbox code

<input className='toggle' id='darkmode' type='checkbox' onChange={handleModeChange} defaultChecked={darkMode} />

enter image description here




Aucun commentaire:

Enregistrer un commentaire