我有以下操作代码:
let nextTodoId = 0
export const addTodo = text => ({
type: 'ADD_TODO',
id: nextTodoId++,
text
})
export const setVisibilityFilter = filter => ({
type: 'SET_VISIBILITY_FILTER',
filter
})
export const toggleTodo = id => ({
type: 'TOGGLE_TODO',
id
})
export const getResult = () => { type: 'GET_RESULT' }
export const VisibilityFilters = {
SHOW_ALL: 'SHOW_ALL',
SHOW_COMPLETED: 'SHOW_COMPLETED',
SHOW_ACTIVE: 'SHOW_ACTIVE'
}
当“getResult”被调度时,我收到此错误:“操作必须是普通对象”。
我不是返回这样的对象吗?
export const getResult = () => { type: 'GET_RESULT' }
如果我将上面的内容更改为:
export const getResult = { type: 'GET_RESULT' }
那就一切都好
即使使用可能的解决方案修改代码后,我仍然收到错误
最佳答案
将对象括在大括号中,否则函数将返回未定义。
export const getResult = () => ({ type: 'GET_RESULT' });
您还需要在 dispatch
中调用 getResult
函数。
getResult: () => dispatch(getResult())
关于javascript - Redux 操作必须是普通对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49557771/