javascript – react js Array.prototype.filter() expects a value to be returned at the end of arrow function
Array.prototype.filter expects a value to be returned from within the callback function implying whether to keep or reject the current item value
However in your callback function you have if-else-if block where you return the value but if none of the if or else-if conditions match, you don’t return anything which what the error points
You can return false if none of your if or else-if condition matches
Try below:
{product
.filter((item) => {
if (search.toString().toLowerCase()) {
return item;
} else if (
item.name.toLowerCase().includes(search.toString().toLowerCase())
) {
return item;
}
return false;
})
Read more here: Source link