Skip to content

Commit 17caa86

Browse files
committed
Fix issue in flat list
1 parent 7ec08ee commit 17caa86

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

example/nestedListView/NodeView.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ export default class NodeView extends React.PureComponent {
1818
}
1919

2020
onNodePressed = (node: any) => {
21-
const newState = rootChildren = this.state.data.map((child, index) => {
22-
return this.props.searchTree(this.state.data[index], node)
23-
})
24-
25-
this.setState({data: newState})
21+
if (this.state.data) {
22+
const newState = rootChildren = this.state.data.map((child, index) => {
23+
return this.props.searchTree(this.state.data[index], node)
24+
})
25+
26+
this.setState({data: newState})
27+
}
28+
2629
this.props.onNodePressed(node)
2730
}
2831

@@ -32,7 +35,7 @@ export default class NodeView extends React.PureComponent {
3235

3336
return (
3437
<View onLayout={onLayout}>
35-
<TouchableOpacity onPress={() => onNodePressed(node)}>
38+
<TouchableOpacity onPress={() => this.onNodePressed(node)}>
3639
{renderNode()}
3740
</TouchableOpacity>
3841
{node.opened && this.state.data

0 commit comments

Comments
 (0)