Antd tree clears the selected treenode

For the tree component under

antd form, after one of the treenode is selected, close the window and open it again. The previously selected treenode is still selected. How can I empty the selected treenode? Thank you!

<div>
   <h4></h4>
        <Tree className="rolesTree"
            checkable
            onCheck={this.onCheck}
            defaultExpandAll={true}
            loadData={this.onLoadData}
         >
          {this.renderTreeNodes(roles)}
        </Tree>
</div>

Mar.05,2021

didn't you change the state to re-render the page when you close the window?


problems like this should immediately come to mind controlled and uncontrolled components.
so you can modify the Tree to be subject to recent components.


state = {
checkedKeys:[]
}

in the form tree component

<Tree className="rolesTree"
      checkable
      onCheck={this.onCheck}
      checkedKeys={checkedKeys}
      defaultExpandAll={true}
      loadData={this.onLoadData}
    >
      {this.renderTreeNodes(roles)}
    </Tree>

that's how it's solved. I am not familiar with react and antd, just now, so I am learning to do it now. Thank you

Menu