Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Unable to expand/collapse all nodes after initial render #112

Open
jeremypeters opened this issue Jul 24, 2018 · 3 comments
Open

Unable to expand/collapse all nodes after initial render #112

jeremypeters opened this issue Jul 24, 2018 · 3 comments

Comments

@jeremypeters
Copy link

I want to use local state to control whether the all the nodes are expanded or collapsed. If I set a local state variable to true and then return that in an an anonymous function assigned to shouldExpandNode() then everything works as expected. If I change this local state variable to false however though the render() lifecycle method is triggered but all the nodes remain expanded.

I'm possibly missing something obvious.

@jeremypeters
Copy link
Author

The issue seems to be in src/JSONNestedNode.js:

  componentWillReceiveProps(nextProps) {
    const nextState = getStateFromProps(nextProps);
    if (getStateFromProps(this.props).expanded !== nextState.expanded) {
      this.setState(nextState);
    }
  }

If the conditional is removed, everything works as expected.

@lvybriage
Copy link

hi,
<JSONTree
hideRoot={true}
// shouldExpandNode={() => }
getItemString={() => ()}
data={record.description}
/>
About this function shouldExpandNode, how can I use it?
I want JSONTree render the object in expanding.

@3crazyspecial
Copy link

<CompareJSONTree
   shouldExpandNode={() => true}
   data={item}
/>

Can only be used in this way

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants