We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Setting state in nodeSelected event causes selected node to get deselected

when i set state in nodeSelected event, it makes selected node deselect, as if it intervene the event.
My concstructor:
constructor(props) {
      super(props);
     this.onNodeSelected = this.onNodeSelected.bind(this);
}

My render looks like:
         
    <TreeViewComponent
                        id='categoryTreeView'
                        loadOnDemand={false}
                        fullRowSelect={false}
                        fields={{
                            dataSource,
                            id: 'mediaFolderId',
                            text: 'Name',
                            parentID: 'parentFolderId',
                            hasChildren: 'hasChild'
                                  }}
                        className='syncfusion-tree-view'
                      nodeSelected={ this.onNodeSelected }
                        ref={element => this.treeViewElement = element}
                    />

updating state:
    onNodeSelected = () => {
          this.setState({ viewAllButton: true});
    }

could you please let me know what i'm doing wrong. I even tried redux action to update state, but i get the same result

3 Replies

KR Keerthana Rajendran Syncfusion Team December 5, 2019 11:11 PM

Hi Niloofar, 
  
Thanks for contacting Syncfusion support. 
  
We have checked your reported problem in TreeView component with your shared code. You have assigned fields settings inside the render method and because of this the component was re-rendered every time we make a change using setState method. To resolve this issue, give the fields settings outside of the render method. We have prepared sample for your convenience. kindly refer to the below link for the sample. 
  
  
  
Please let us know if you have any concerns. 
  
  
Regards, 
Keerthana.  



NI Niloofar December 6, 2019 05:51 AM

That fixed my problem, thank you.


KR Keerthana Rajendran Syncfusion Team December 9, 2019 01:03 AM

Hi Niloofar,  
 
Most welcome. We are glad to hear that the provided solution helped you to achieve your requirement. Please get back to us if you need any further assistance on this. 
 
Regards, 
Keerthana.  


Loader.
Live Chat Icon For mobile
Up arrow icon