0

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}
              />
            );
          })}

1 Answer 1

1

What does the <Checkbox /> component look like? Checkboxes in react use the checked attribute for storing boolean state, example <input type="checkbox" checked={xmasCamp2019} />

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I thought it was the value that needed to be set in stead of checked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.