nyx*_*nyx 2 react-native redux react-redux
想知道我的代码出了什么问题,当我尝试使用 redux 分派操作时,它给出了错误,这是我的 reducer.js 代码
import {UPDATE_LOGIN} from './constants'
const initialState = {
isLogged:false
};
const reducer = (state = initialState, action) => {
switch (action.type) {
case UPDATE_LOGIN:
return [
...state,
{
isLogged:action.isLogged
}
];
default:
return state;
}
}
export default reducer;
Run Code Online (Sandbox Code Playgroud)
it gives a Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a Symbol.iterator method.
Your state is an object, and you try to destructure it as an array. In addition, you try to include the object, instead of changing the property. Try this:
const reducer = (state = initialState, action) => {
switch (action.type) {
case UPDATE_LOGIN:
return {
...state,
isLogged: action.isLogged
};
default:
return state;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
862 次 |
最近记录: |