Why is children.length resulting in Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'length') especially since the value of children.length is successfully displayed on the console?
const getParentId = (childId) => {
var queue = [ds]
while(queue.length > 0){
const children = queue[0].children
queue.push(children)
console.log("children.length = "+children.length)
for (let i = 0; i < children.length; i++){
if (children[i].id === childId) {return queue[0].id}
}
queue.shift()
}
}
const addSiblingNodes = async () => {
const child = [...selectedNodes][0]
const childId = child.id
const newNodes = getNewNodes()
await dsDigger.addSiblings(childId, newNodes);
setDS({ ...dsDigger.ds });
console.log("the parent of "+childId +" is "+ getParentId(childId))
};