@@ -97,7 +97,7 @@ class FilterExample extends React.Component {
97
97
] ,
98
98
filterText : '' ,
99
99
nodesFiltered : nodes ,
100
- nodes
100
+ nodes,
101
101
} ;
102
102
103
103
this . onCheck = this . onCheck . bind ( this ) ;
@@ -114,37 +114,41 @@ class FilterExample extends React.Component {
114
114
onExpand ( expanded ) {
115
115
this . setState ( { expanded } ) ;
116
116
}
117
-
118
- nodeFilter ( node : Node ) {
119
- const children = ( node . children || [ ] ) . map ( this . nodeFilter ) . filter ( c => c !== null ) ;
120
117
121
- return node . label . indexOf ( this . state . filterText ) !== - 1 || children . length ? { ...node , children : children } : null ;
118
+ setFilterText ( e ) {
119
+ this . setState ( { filterText : e . target . value } , this . filterTree ) ;
122
120
}
123
121
124
- filterTree ( ) {
122
+ filterTree ( ) {
125
123
if ( ! this . state . filterText ) {
126
- return this . setState ( {
127
- nodesFiltered : this . state . nodes
128
- } ) ;
124
+ this . setState ( prevState => ( {
125
+ nodesFiltered : prevState . nodes ,
126
+ } ) ) ;
127
+
128
+ return ;
129
129
}
130
130
131
- const nodesFiltered = this . state . nodes . map ( this . nodeFilter ) . filter ( n => n !== null ) ;
131
+ const nodesFiltered = prevState => (
132
+ { nodesFiltered : prevState . nodes . map ( this . nodeFilter ) . filter ( n => n !== null ) }
133
+ ) ;
132
134
133
- this . setState ( {
134
- nodesFiltered : nodesFiltered
135
- } ) ;
135
+ this . setState ( nodesFiltered ) ;
136
136
}
137
-
138
- setFilterText ( e ) {
139
- this . setState ( { filterText : e . target . value } , this . filterTree ) ;
137
+
138
+ nodeFilter ( node ) {
139
+ const children = ( node . children || [ ] ) . map ( this . nodeFilter ) . filter ( c => c !== null ) ;
140
+
141
+ return node . label . indexOf ( this . state . filterText ) !== - 1 || children . length ?
142
+ { ...node , children } :
143
+ null ;
140
144
}
141
145
142
146
render ( ) {
143
147
const { checked, expanded } = this . state ;
144
148
145
149
return (
146
150
< div >
147
- < input type = 'text' placeholder = 'Search' value = { this . state . filterText } onChange = { this . setFilterText } />
151
+ < input type = 'text' placeholder = 'Search' value = { this . state . filterText } onChange = { this . setFilterText } />
148
152
< CheckboxTree
149
153
checked = { checked }
150
154
expanded = { expanded }
0 commit comments