3

I have created a Checkbox.Group using ant design, based on the values from API, the following checkboxes should get checked.

const options = [
  { label: 'Apple', value: 'Apple' },
  { label: 'Pear', value: 'Pear' },
  { label: 'Orange', value: 'Orange' }
];

const valuesFromApi = ['Apple', 'Pear'];

ReactDOM.render(
  <div>
    <Checkbox.Group
      options={options}
      onChange={onChange}
      value={valuesFromApi}
    />
  </div>,
  document.getElementById('container')
);

Edit aged-cdn-u6jf2

1
  • Can you show the code related to this question? Commented Jul 22, 2019 at 11:58

2 Answers 2

8

You need to specify value property for Checkbox-Group

value - Used for setting the currently selected value.

const options = [
  { label: 'Apple', value: 'Apple' },
  { label: 'Pear', value: 'Pear' },
  { label: 'Orange', value: 'Orange' }
];

const valuesFromApi = ['Apple', 'Pear'];

ReactDOM.render(
  <div>
    <Checkbox.Group
      options={options}
      onChange={onChange}
      value={valuesFromApi}
    />
  </div>,
  document.getElementById('container')
);
Sign up to request clarification or add additional context in comments.

Comments

1

I have made a working example for you.

What it does is give you the ability to store the checked values from the CheckBox Group and store them in the state for possible future use.

CodeSandBox.

Please let me know if something is not clear enough.

PS: I have used destruction for defining variables.

1 Comment

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.