mercredi 7 octobre 2020

React checkbox not initialy taking value of object

I have a project where I need to use a checkbox. My data comes from a database and gets injected in an state object. This object contains a list of children and each child contains a boolean called 'xmasCamp2019'. But the first time this code gets rendered the checkbox doesn't take over the value of the boolean.

But when I do a log of the boolean it outputs true. When the onChange is called the boolean of that child is swapped and then the checkbox does gets checked.

{this.state.selectedRegistration.childrenArray.map((child) => {
            console.log(child.xmasCamp2019);
            return (
              <FormControlLabel
                key={child.index}
                value={child.xmasCamp2019}
                onChange={(event, value) =>
                  this.selectChild(child.index, value)
                }
                control={
                  <Checkbox name="Insurance" value={child.xmasCamp2019} />
                }
                label={child.name}
              />
            );
          })}



Aucun commentaire:

Enregistrer un commentaire