react-json-tree icon indicating copy to clipboard operation
react-json-tree copied to clipboard

Unable to expand/collapse all nodes after initial render

Open jeremypeters opened this issue 7 years ago • 3 comments
trafficstars

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 avatar Jul 24 '18 16:07 jeremypeters

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.

jeremypeters avatar Jul 25 '18 10:07 jeremypeters

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.

lvybriage avatar Jul 30 '18 07:07 lvybriage

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

Can only be used in this way

3crazyspecial avatar Aug 20 '19 13:08 3crazyspecial