【发布时间】:2019-02-17 19:31:33
【问题描述】:
我正在尝试通过单击从 dom 中删除一个元素。我在没有 redux thunk 的情况下没有问题,但现在我遇到了问题。我的减速器不知道状态。如何让他知道物品是什么?
行动:
export function deleteItem(index) {
return {
type: 'DELETE_ITEM',
index
};
}
我的减速器显示未定义。
export function deleteItem(state = [], action) {
switch (action.type) {
case 'DELETE_ITEM':
const copy = state.items.slice()
console.log(copy)
default:
return state;
}
}
这是我的实际代码https://github.com/KamilStaszewski/flashcards/tree/develop/src
【问题讨论】:
-
deleteItem 被触发了吗?我认为问题不在上面列出的代码上。
-
动作被触发。它正在通过索引。问题在于reducer,他不知道应用程序的实际状态(state.items)
-
为什么要从
store本身中删除它?您可以将其从组件状态中删除。为什么要从store中删除? -
正确的做法是什么?
-
@Abinthaha : 如果商品应该从商店中使用,它们不应该也从商店中移除吗?
标签: reactjs redux redux-thunk