Skip to content

Commit 2160aaa

Browse files
authored
Update JSONNestedNode.tsx to better handle sparse array inputs
1 parent 750046c commit 2160aaa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/react-json-tree/src/JSONNestedNode.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface Entry {
2727
}
2828

2929
function isRange(rangeOrEntry: Range | Entry): rangeOrEntry is Range {
30-
return (rangeOrEntry as Range).to !== undefined;
30+
return (rangeOrEntry as Range)?.to !== undefined;
3131
}
3232

3333
function renderChildNodes(
@@ -54,6 +54,10 @@ function renderChildNodes(
5454
from,
5555
to,
5656
).forEach((entry) => {
57+
// Don't process null/undefined entries, which can come from sparse arrays
58+
if(!entry) {
59+
return
60+
}
5761
if (isRange(entry)) {
5862
childNodes.push(
5963
<ItemRange

0 commit comments

Comments
 (0)