From f78f97a56834f911cb1852a887fc2d4f18607dc8 Mon Sep 17 00:00:00 2001 From: Matt Vague Date: Sun, 2 May 2021 14:11:25 -0700 Subject: [PATCH] Fix example in readme which doesn't handle no children --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b1a0a81..1f9c5b5 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ const treeNodes = [ const getNodeData = (node, nestingLevel) => ({ data: { id: node.id.toString(), // mandatory - isLeaf: node.children.length === 0, + isLeaf: !!node.children, isOpenByDefault: true, // mandatory name: node.name, nestingLevel, @@ -95,6 +95,8 @@ function* treeWalker() { // the `getNodeData` function constructed, so you can read any data from it. const parent = yield; + if (!parent.node.children) continue + for (let i = 0; i < parent.node.children.length; i++) { // Step [3]: Yielding all the children of the provided component. Then we // will return for the step [2] with the first children.