react-json-tree
react-json-tree copied to clipboard
Unable to expand/collapse all nodes after initial render
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.
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.
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.
<CompareJSONTree
shouldExpandNode={() => true}
data={item}
/>
Can only be used in this way