'动作'在reducer中没有定义 - React,Redux

时间:2018-05-29 15:26:20

标签: reactjs redux

我已经设置了减速机,但是控制台却抱怨“' action'未定义no-undef

import { getName } from '../actions';
let defaultState={
 name: "Sam"
}
const mainReducer=(state = defaultState, simpleAction)=>{
if (action.type === "CHANGE_NAME") {
return{
  ...state,
  name: action.name
}

} else {
return{
  ...state
}
}
}

export default mainReducer

2 个答案:

答案 0 :(得分:0)

只需将simpleAction更改为action

即可

答案 1 :(得分:0)

做到这样的事情:

import { getName } from '../actions';
let defaultState = { name: "Sam" }
const mainReducer = (state = defaultState, action) => {
    if (action.type === "CHANGE_NAME") {
        return { ...state, name: action.name }
    }
    else {
        return { ...state }
    }
}
export default mainReducer