[英]Searchbox dosen't work when the input is erased react redux
I'm practing react redux and I'm making a simple CRUD.我正在练习反应 redux 并且我正在制作一个简单的 CRUD。 I create a searchbox input, and works fine, but when I erased the input, the table with the data dosen 't update.
我创建了一个搜索框输入,并且工作正常,但是当我删除输入时,带有数据的表不会更新。 I alrready try save the result into the "search" in the initialState, but still dosen't work.
我已经尝试将结果保存到初始状态的“搜索”中,但仍然无法正常工作。 what I'm doing wrong?
我做错了什么? Thanks!
谢谢!
I upload my code here:我在这里上传我的代码:
https://codesandbox.io/s/silly-wood-5ni19?fontsize=14&hidenavigation=1&theme=dark https://codesandbox.io/s/silly-wood-5ni19?fontsize=14&hidenavigation=1&theme=dark
Try to change to:尝试更改为:
case "SEARCH_DATA": {
const { event } = action.payload;
let res = [];
if (event) {
res = state.data.filter( el => el.name.toLowerCase().includes(event));
}
return {
...state,
data : res, // here is pass the result of the filter fn
loading: true
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.