gpt4 book ai didi

redux reducer 返回未定义处理

转载 作者:行者123 更新时间:2023-12-02 08:22:58 24 4
gpt4 key购买 nike

我的 reducer 喜欢:

const initialState = [
{
fname: null,
lname: false,
}
]

export default function login(state = initialState, action) {
switch (action.type) {
case LOGIN:
console.log("actions")
console.log(action)
console.log("reducers")
return
[{
fname: action.fname,
lname: action.lname,
}]
default:
return state
}
}

在这里,我使用 fnamelname 获取操作对象,但这给了我错误提示 .. Uncaught Error: Reducer "login"returned undefined handling "登录”。要忽略某个操作,您必须显式返回之前的状态。

为什么会出现此错误?

最佳答案

替换:

 return
[

收件人:

 return [

因为first就像return;(js在行末添加;)

关于redux reducer 返回未定义处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35056062/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com