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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Setting state in nodeSelected event causes selected node to get deselected

Thread ID:

Created:

Updated:

Platform:

Replies:

149696 Dec 5,2019 06:38 PM UTC Dec 9,2019 09:03 AM UTC React - EJ 2 3
loading
Tags: Treeview
Niloofar
Asked On December 5, 2019 06:38 PM UTC

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

Keerthana Rajendran [Syncfusion]
Replied On December 6, 2019 07:11 AM UTC

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.  


Niloofar
Replied On December 6, 2019 01:51 PM UTC

That fixed my problem, thank you.

Keerthana Rajendran [Syncfusion]
Replied On December 9, 2019 09:03 AM UTC

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.  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon