我想声明动作的有效载荷但它失败了
i want to declare payload of action but it's failed
我在 action redux slice reducer 中添加 payload 时遇到了问题,我在互联网上进行了搜索,但我没有找到解决这个问题的解决方案,所以我的代码 reducer:
topicsSlice code:
import {createSlice} from "@reduxjs/toolkit";
const topicsSlice = createSlice({
name : "topics",
initialState: {
topics:{}
},
reducers: {
addTopic: (state, action={type: "topics/addTopic",payload: {id, name, icon}}) => {
const newTopic = {id: id, name: name, icon: icon}
state.topics = {...state.topics, id: newTopic};
}
}
});
export const selectedTopics = (state) => state.topics.topics;
export const {addTopic} = topicsSlice.actions;
export default topicsSlice.reducer;
这里的解构就像
addTopic: (state, {payload: {id, name, icon}}) => {
我在 action redux slice reducer 中添加 payload 时遇到了问题,我在互联网上进行了搜索,但我没有找到解决这个问题的解决方案,所以我的代码 reducer:
topicsSlice code:
import {createSlice} from "@reduxjs/toolkit";
const topicsSlice = createSlice({
name : "topics",
initialState: {
topics:{}
},
reducers: {
addTopic: (state, action={type: "topics/addTopic",payload: {id, name, icon}}) => {
const newTopic = {id: id, name: name, icon: icon}
state.topics = {...state.topics, id: newTopic};
}
}
});
export const selectedTopics = (state) => state.topics.topics;
export const {addTopic} = topicsSlice.actions;
export default topicsSlice.reducer;
这里的解构就像
addTopic: (state, {payload: {id, name, icon}}) => {