React JS 根据年份过滤产品
我想根据年份过滤产品,我制作了
组件,其中有
const filteredYearValue = productListItems.filter(e => {
return e.date.getFullYear().toString() === filterValue;
})
但我很少有困惑将过滤后的值从ItemDateFilter.js
获取到<代码>ProductITems.js。
这是我的代码 - https://github.com/mohitdevelops/react-lessons/tree/主/产品应用
I wanna filter the products according to the year, I made <ItemDateFilter />
component where I have the <select>
menu to select the year. I know the code to compare the date of product with the filtered year here is comparing code:-
const filteredYearValue = productListItems.filter(e => {
return e.date.getFullYear().toString() === filterValue;
})
but I have few confusions to get the filtered value from ItemDateFilter.js
to ProductITems.js
.
Here is my code -
https://github.com/mohitdevelops/react-lessons/tree/main/product-app
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将状态从 ItemDateFilter 组件移动到 App 组件
,并通过 props 将 onFilterDateValue 函数传递给 ItemDateFilter 组件
,并在传递到 ProductListItems 组件之前过滤列表
You can move the state from ItemDateFilter component to App Component
And pass the onFilterDateValue function to ItemDateFilter component through props
And filter the list before passing to ProductListItems component
您修改 App.js 、 ProductItems.js 、 ItemDateFilter.js 以下代码
You modify App.js , ProductItems.js, ItemDateFilter.js the following below code