美文网首页
redux Actions may not have an un

redux Actions may not have an un

作者: 天渺工作室 | 来源:发表于2021-03-19 14:35 被阅读0次

react-redux 报错

Actions may not have an undefined "type" property. Have you misspelled a constant?
image.gif

出现类似的错误,很大几率是因为redux 操作action 动作时候的type 名称问题

image image.gif image image.gif

检查action 中的type 是否和reducer 操作中的type 名称是一致

两处用到的 type 需要一致

// ./action.js 
// 类型为type:types.USER
export const userAction=(data)=>({type:"类型名称",data});

// ./reducer.js
let token =null;

export default function Token(_token=token,action){
    //解构中的type用来做判断条件
    const {type,data}=action;
    switch(type){
        case "判断条件":
        return data;
        default:
        return _token;    
    }

}
image.gif

相关文章

网友评论

      本文标题:redux Actions may not have an un

      本文链接:https://www.haomeiwen.com/subject/nsivcltx.html