I've got a problem with my function, after calling it inside an if statement it works sometimes but it doesn't return the last return it starts again with new value.
Here's data I render:
listData: [
[
{id: 1, title: 'list1'},
{id: 2, title: 'list2'},
],
{id: 3, title: 'list3'},
];
And function:
isArray(a) {
return (!!a) && (a.constructor === Array);
}
renderList(item, options) {
if (this.isArray(item) === true) {
item.map((child, childIndex) => {
this.renderList(child, options)
})
}
return (
<List item={item} />
)
}
Array.isArray, or an actual polyfill, don't roll your own. Also, the recursive call is unnecessary, just return a div with the lists mapped inside it.item.map()call doesn't have any effect. Even though the children might not be arrays and thus get returned, the result of themap()call is discarded.