1

我在使用createActions时遇到问题,如果只使用createAction一切正常,但如果我尝试使用 createActions 应用程序会显示错误......

未处理的拒绝 (TypeError):Object(...) 不是函数

在我所有具有调度方法的函数中,仅适用于 createAction

import { createAction, createActions } from 'redux-actions'
// Types
import { ADD_TASK } from '../types/todo.types'
import { SHOW_TASKS } from '../types/todo.types'

// export const addTaskAction = createAction(ADD_TASK)
// export const showAllTasksAction = createAction(SHOW_TASKS)

// * Refactor to createActions

export const { addTaskAction, showAllTasksAction } = createActions(
  ADD_TASK,
  SHOW_TASKS,
)
Unhandled Rejection (TypeError): Object(...) is not a function
_callee$
src/shared/routes/private/PrivateRoutes.routes.js:19
  16 |   getAllTasks()
  17 | }, [])
  18 | 
> 19 | async function getAllTasks() {
     | ^  20 |   const result = await todo.getAllTasks()
  21 |   return dispatch(showAllTasksAction(result))
  22 | }

4

1 回答 1

0

我也遇到了同样的情况,问题是常量需要匹配动作(使用驼峰式),这样 createActions 函数可以将动作与字符串匹配

于 2021-09-23T15:35:25.020 回答