Reputation: 749
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} />
)
}
Upvotes: 1
Views: 122
Reputation: 606
renderList(item, options) {
if ( Array.isArray(item) ) {
return item.map( (child, childIndex) => {
return this.renderList(child, options)
})
} else {
return (
<List item={item} />
)
}
}
Upvotes: 3
Reputation: 1497
Please try this:
if (this.isArray(item) === true) {
return item.map((child, childIndex) => {
return this.renderList(child, options)
})
}
Upvotes: 1