react-native - Unable to delete item from redux store, payload is a long list of strings
问题描述
I'm trying to delete an item from the store using useDispatch from redux. However the payload which is sent through via action is undefined. Here is my reducer:
export const DELETE_ITEM = 'DELETE_ITEM';
case DELETE_ITEM:
return {
...state,
items: state.items.filter((item, item_code) => item_code !== payload),
};
And Here is my action:
//delete items
export const deleteItemAction = (item_code) => {
return {type: DELETE_ITEM, payload: item_code};
};
And Finally my function & component
const dispatch = useDispatch();
const delete_item = (item_code: any) => {
dispatch(deleteItemAction({item_code: item_code}));
console.log(item_code);
};
<FlatList
data={items}
keyExtractor={items.item_code}
renderItem={({item}) => (
<View>
<Text>{item.item_id}</Text>
<Text>{item.item_type}</Text>
<Text>{item.item_code}</Text>
<Text>{item.item_description}</Text>
<Text>{item.cost_price}</Text>
<Text>{item.quantity}</Text>
<Text>{item.selling_price}</Text>
<View>
<Button title="Delete" onPress={delete_item} />
<Button title="Edit" onPress={() => {}} />
</View>
</View>
)}
/>
解决方案
I've found a temporary fix,
<Button title='Delete' onPress={() => {
dispatch(deleteItemAction(item.item_code));
}}
推荐阅读
- flutter - 如何在不使用构建器的情况下自动滚动页面视图并产生一些延迟?
- r - 需要向量化字符串上的函数
- laravel - Laravel 与多个函数的多对多关系
- android - Kotlin 中有垃圾收集器吗?
- javascript - Javascript:按值对对象进行排序
- powershell - 在一次尝试/捕获中捕获多个错误
- sas - 重新标记年月变量以通知 Proc Freq 顺序
- video-streaming - 如何通过 rtp 在 h264 中更改与 Idr 数据包相关的数据包?
- c# - 将 2d 对象从 a 点移动到 b 点而不改变其旋转
- apache-camel - 您什么时候会使用企业服务总线和像 Apache Camel 这样的集成框架?