我想向减速器添加一个案例,我想在其中设置完整状态,而不是任何特定属性。
更新特定属性 [ SET_SELECTED_PAGE,UPDATE_MESSAGE_DISPLAYED
] 工作正常。但是当我尝试时SET_INIT_DATA
我得到错误Parsing error: Unexpected token, expected ","
。有效负载SET_INIT_DATA
将具有完整的 json。
我的状态会像
{
"user": "",
"selectedPage": "home",
"message": "Message from admin",
...
}
代码:
const reducer = (state, action) => {
switch (action.type) {
case "SET_SELECTED_PAGE":
return {
...state,
selectedPage: action.payload
};
case "UPDATE_MESSAGE_DISPLAYED":
return {
...state,
messageDisplayed: action.payload
};
case "SET_INIT_DATA":
return {
action.payload // getting error Parsing error: Unexpected token, expected ","
};
default:
throw new Error();
}
};