[英]filter function error :: Uncaught Error: Objects are not valid as a React child .... use an array instead
Trying to display results after applying filter function.I need to compare with searchValue.but it gives Error在应用过滤器 function 后尝试显示结果。我需要与 searchValue 进行比较。但它给出了错误
{noteList.filter((obj,index) => <Card
noteObj={obj.Name.toLowerCase().includes(searchValue)}
index={index}
deleteNote={deleteNote}
updateNoteArray={updateNoteArray}
/>)
}
You need to first filter out the options from noteList
array according to your condition and then apply a map
over it.您需要首先根据您的条件从
noteList
数组中过滤掉选项,然后在其上应用map
。
{
noteList.filter((obj) => obj.Name.toLowerCase().includes(searchValue))
.map((item,index) => <Card
noteObj={item}
index={index}
deleteNote={deleteNote}
updateNoteArray={updateNoteArray}
/>
)
}
noteList.filter((obj)=>obj.Name.toLowerCase().includes(searchValue))
This will return a new array which contains all the names which will includes searchValue . noteList.filter((obj)=>obj.Name.toLowerCase().includes(searchValue))
这将返回一个新数组,其中包含所有将包含searchValue的名称。 Then you can use this resultant array to display your result然后你可以使用这个结果数组来显示你的结果
use map
not filter
使用
map
不filter
{ noteList
.filter((obj, index)=>{ return obj.Name.toLowerCase().includes(searchValue)})
.map((obj,index) => <Card
noteObj={obj}
index={index}
deleteNote={deleteNote}
updateNoteArray={updateNoteArray}
/>)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.