Skip to content

Commit 640b745

Browse files
authored
Update README.md
Fix node not defined error in README.md examples
1 parent e1362ee commit 640b745

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function* treeWalker(refresh) {
8484
const isOpened = yield refresh
8585
? {
8686
id,
87-
isLeaf: children.length === 0,
87+
isLeaf: children?.length === 0,
8888
isOpenByDefault: true,
8989
name,
9090
nestingLevel,
@@ -93,13 +93,13 @@ function* treeWalker(refresh) {
9393

9494
// Basing on the node openness state we are deciding if we need to render
9595
// the child nodes (if they exist).
96-
if (node.children.length !== 0 && isOpened) {
96+
if (children?.length !== 0 && isOpened) {
9797
// Since it is a stack structure, we need to put nodes we want to render
9898
// first to the end of the stack.
99-
for (let i = node.children.length - 1; i >= 0; i--) {
99+
for (let i = children?.length - 1; i >= 0; i--) {
100100
stack.push({
101101
nestingLevel: nestingLevel + 1,
102-
node: node.children[i],
102+
node: children[i],
103103
});
104104
}
105105
}
@@ -253,18 +253,18 @@ function* treeWalker(refresh) {
253253
// object.
254254
defaultHeight: 30,
255255
id,
256-
isLeaf: children.length === 0,
256+
isLeaf: children?.length === 0,
257257
isOpenByDefault: true,
258258
name,
259259
nestingLevel,
260260
}
261261
: id;
262262

263-
if (node.children.length !== 0 && isOpened) {
264-
for (let i = node.children.length - 1; i >= 0; i--) {
263+
if (children?.length !== 0 && isOpened) {
264+
for (let i = children?.length - 1; i >= 0; i--) {
265265
stack.push({
266266
nestingLevel: nestingLevel + 1,
267-
node: node.children[i],
267+
node: children[i],
268268
});
269269
}
270270
}

0 commit comments

Comments
 (0)