我已经设置了减速机,但是控制台却抱怨“' 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
答案 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