Skip to content

Commit 5f1e8e8

Browse files
committed
Fix an issue getting root children
1 parent 40b4ba5 commit 5f1e8e8

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

.eslintcache

Lines changed: 0 additions & 1 deletion
This file was deleted.

.npmignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
example
2-
3-
node_modules
2+
flow-typed
3+
node_modules
4+
__snapshots__

index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default class NestedListView extends React.PureComponent<Props, State> {
1919
id: shortid.generate(),
2020
items: this.props.data
2121
? this.props.data.map((child: Node, index: number) =>
22-
this.generateIds(this.props.data[index]),
22+
this.generateIds(this.props.data[index])
2323
)
2424
: [],
2525
name: 'root',
@@ -40,7 +40,7 @@ export default class NestedListView extends React.PureComponent<Props, State> {
4040

4141
if (children) {
4242
node[childrenName] = children.map((child, index) =>
43-
this.generateIds(children[index]),
43+
this.generateIds(children[index])
4444
)
4545
}
4646

@@ -49,7 +49,15 @@ export default class NestedListView extends React.PureComponent<Props, State> {
4949
return node
5050
}
5151

52-
getChildrenName = (node: Node) => this.props.getChildrenName(node)
52+
getChildrenName = (node: Node) => {
53+
if (node.name === 'root') {
54+
return 'items'
55+
}
56+
57+
return this.props.getChildrenName
58+
? this.props.getChildrenName(node)
59+
: 'items'
60+
}
5361

5462
render = () => {
5563
if (!this.props.getChildrenName) {

0 commit comments

Comments
 (0)