React checkbox tree expand and check button not responding

I have this code :

render() {
    let state = {
        checked: [
            'catc'
        ],
        expanded: [
            'cata',
            'catb'
        ],
    };
<CheckboxTree
   nodes={this.props.chosenCategory.children}
   checked={state.checked}
   expanded={state.expanded}
   onCheck={checked => this.setState({ checked })}
   onExpand={expanded => this.setState({ expanded })}
/>

So I have the result like this :
enter image description here

But when I click on check or expand the list doesn’t respond. Can anybody help me please? Thanks in advance.

After putting state outside of render() :

enter image description here

this.props.chosenCategory.children :

"id": 26578,
                "label": "CatA",
                "value": "cata",
                "children": [
                    {
                        "id": 26579,
                        "label": "CatB",
                        "value": "catb",
                        "children": [
                            {
                                "id": 26580,
                                "label": "CatC",
                                "value": "catc",
                                "children": []
                            }
                        ]
                    }
                ]

102 thoughts on “React checkbox tree expand and check button not responding”

  1. You need to define state outside of render method :

      state = {
        checked: [
          'catc'
        ],
        expanded: [
          'cata',
          'catb'
        ],
      };
    
      render() {
        return (
          <CheckboxTree
            nodes={this.props.chosenCategory.children}
            checked={this.state.checked}
            expanded={this.state.expanded}
            onCheck={checked => this.setState({ checked })}
            onExpand={expanded => this.setState({ expanded })}
          />
        );
      }
    
    Reply
  2. Pingback: buying viagra
  3. Pingback: cialis everyday
  4. Pingback: sildenafil dosage

Leave a Comment