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) {
     this.onNodeSelected = this.onNodeSelected.bind(this);

My render looks like:
                            id: 'mediaFolderId',
                            text: 'Name',
                            parentID: 'parentFolderId',
                            hasChildren: 'hasChild'
                      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 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. 

NI Niloofar December 6, 2019 01:51 PM UTC

That fixed my problem, thank you.

KR Keerthana Rajendran Syncfusion Team 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. 

Live Chat Icon For mobile
Up arrow icon