@@ -58,6 +58,17 @@ function renderChildNodes(props, from, to) {
58
58
return childNodes ;
59
59
}
60
60
61
+ function getStateFromProps ( props ) {
62
+ // calculate individual node expansion if necessary
63
+ const expanded = props . shouldExpandNode && ! props . isCircular ?
64
+ props . shouldExpandNode ( props . keyPath , props . data , props . level ) :
65
+ false ;
66
+ return {
67
+ expanded,
68
+ createdChildNodes : false
69
+ } ;
70
+ }
71
+
61
72
export default class JSONNestedNode extends React . Component {
62
73
static propTypes = {
63
74
getItemString : PropTypes . func . isRequired ,
@@ -88,14 +99,15 @@ export default class JSONNestedNode extends React.Component {
88
99
89
100
constructor ( props ) {
90
101
super ( props ) ;
102
+ this . state = getStateFromProps ( props ) ;
103
+ }
91
104
92
- // calculate individual node expansion if necessary
93
- const expanded = props . shouldExpandNode && ! props . isCircular ?
94
- props . shouldExpandNode ( props . keyPath , props . data , props . level ) : false ;
95
- this . state = {
96
- expanded,
97
- createdChildNodes : false
98
- } ;
105
+ componentWillReceiveProps ( nextProps ) {
106
+ if ( [ 'shouldExpandNode' , 'isCircular' , 'keyPath' , 'data' , 'level' ] . find ( k =>
107
+ nextProps [ k ] !== this . props [ k ] )
108
+ ) {
109
+ this . setState ( getStateFromProps ( nextProps ) ) ;
110
+ }
99
111
}
100
112
101
113
shouldComponentUpdate = shouldPureComponentUpdate ;
@@ -114,7 +126,7 @@ export default class JSONNestedNode extends React.Component {
114
126
labelRenderer,
115
127
expandable
116
128
} = this . props ;
117
- const expanded = this . state . expanded ;
129
+ const { expanded } = this . state ;
118
130
const renderedChildren = expanded || ( hideRoot && this . props . level === 0 ) ?
119
131
renderChildNodes ( { ...this . props , level : this . props . level + 1 } ) : null ;
120
132
0 commit comments