{"record":{"id":"381cf1d8ee7fbc15","repo":"reduxjs/redux","slug":"bindactioncreators-expected-an-object-or-a-functio","errorCode":null,"errorMessage":"bindActionCreators expected an object or a function, but instead received: '${kindOf(actionCreators)}'. Did you write \"import ActionCreators from\" instead of \"import * as ActionCreators from\"?","messagePattern":"bindActionCreators expected an object or a function, but instead received: '(.+?)'\\. Did you write \"import ActionCreators from\" instead of \"import \\* as ActionCreators from\"\\?","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/bindActionCreators.ts","lineNumber":67,"sourceCode":"export default function bindActionCreators<\n  A,\n  M extends ActionCreatorsMapObject<A>\n>(actionCreators: M, dispatch: Dispatch): M\nexport default function bindActionCreators<\n  M extends ActionCreatorsMapObject,\n  N extends ActionCreatorsMapObject\n>(actionCreators: M, dispatch: Dispatch): N\n\nexport default function bindActionCreators(\n  actionCreators: ActionCreator<any> | ActionCreatorsMapObject,\n  dispatch: Dispatch\n) {\n  if (typeof actionCreators === 'function') {\n    return bindActionCreator(actionCreators, dispatch)\n  }\n\n  if (typeof actionCreators !== 'object' || actionCreators === null) {\n    throw new Error(\n      `bindActionCreators expected an object or a function, but instead received: '${kindOf(\n        actionCreators\n      )}'. ` +\n        `Did you write \"import ActionCreators from\" instead of \"import * as ActionCreators from\"?`\n    )\n  }\n\n  const boundActionCreators: ActionCreatorsMapObject = {}\n  for (const key in actionCreators) {\n    const actionCreator = actionCreators[key]\n    if (typeof actionCreator === 'function') {\n      boundActionCreators[key] = bindActionCreator(actionCreator, dispatch)\n    }\n  }\n  return boundActionCreators\n}\n","sourceCodeStart":49,"sourceCodeEnd":84,"githubUrl":"https://github.com/reduxjs/redux/blob/3084fc33bb23ab4cab4796172eafe342da4e73d9/src/bindActionCreators.ts#L49-L84","documentation":"bindActionCreators wraps either a single action creator or a map of them so they auto-dispatch. It throws when the first argument is neither a function nor a non-null object. The hint about import syntax targets the single most frequent cause: a default import that yields undefined when the module exports a namespace.","triggerScenarios":"Calling bindActionCreators(undefined, dispatch) or bindActionCreators(someString, dispatch); default-importing a module that only has named exports so the import value is undefined; destructuring an action-creators object incorrectly and passing the outer module namespace; passing an array instead of an object map.","commonSituations":"Writing `import ActionCreators from './actions'` instead of `import * as ActionCreators from './actions'` when actions.ts uses named exports; renaming an action-creators module and forgetting to update the import; re-export bugs where a barrel file does not actually re-export the symbol; mixing CommonJS require() with ESM where the namespace is nested under .default.","solutions":["Switch the import to a namespace import: `import * as ActionCreators from './actions'` and verify the module uses named exports (export const addTodo = ...).","If the module has a default export, keep `import ActionCreators from './actions'` and confirm the default export is an object of functions.","Before calling, log typeof ActionCreators and Object.keys(ActionCreators) to confirm it is a non-null object whose values are functions.","For CommonJS interop, use ActionCreators.default when require() returns { default: {...}, __esModule: true }."],"exampleFix":"// before (actions.ts uses named exports)\nimport ActionCreators from './actions'          // ActionCreators is undefined\nbindActionCreators(ActionCreators, dispatch)     // throws\n\n// after\nimport * as ActionCreators from './actions'\nbindActionCreators(ActionCreators, dispatch)","handlingStrategy":"validation","validationCode":"const isActionCreatorMap = x =>\n  x !== null && typeof x === 'object' &&\n  Object.values(x).every(v => typeof v !== 'function' || true)\n\nif (typeof actionCreators !== 'function' && !isActionCreatorMap(actionCreators)) {\n  console.error('bindActionCreators: invalid first arg', actionCreators)\n} else {\n  bound = bindActionCreators(actionCreators, dispatch)\n}","typeGuard":"const isActionCreatorsMap = (x): x is Record<string, (...a:any[])=>any> =>\n  x !== null && typeof x === 'object'\nconst isActionCreatorFn = (x): x is (...a:any[])=>any => typeof x === 'function'","tryCatchPattern":"try {\n  bindActionCreators(actionCreators, dispatch)\n} catch (e) {\n  if (/expected an object or a function/.test(e.message)) {\n    console.error('Check your action-creators import:', actionCreators)\n  }\n  throw e\n}","preventionTips":["Use `import * as X from './actions'` for modules with named exports.","Run a quick typeof check on the import before binding.","Prefer named re-exports in barrel files to keep default/namespace semantics unambiguous."],"tags":["redux","bindactioncreators","import","esm","commonjs"],"backgroundTag":null,"analyzedSha":"3084fc33bb23ab4cab4796172eafe342da4e73d9","analyzedAt":"2026-08-12T13:21:41.727Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}