Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redux Toolkit · Function

isActionCreator

isActionCreator is a configurable predicate used by Redux Toolkit's action-creator invariant middleware. It identifies values that should be treated as action creators, including custom action-creator shapes.

How it works

isActionCreator is a configurable type-guard predicate for action-creator invariant middleware. It receives an unknown value and returns whether that value should be treated as an action creator; the middleware can then warn when the creator itself is dispatched instead of its returned action.

Syntax

isActionCreator?: (action: unknown) => action is Function & { type?: unknown }

Parameters

NameTypeDescription
actionunknownThe value to classify as an action creator; its runtime type is unknown.

Returns

A boolean type predicate: action is Function & { type?: unknown } in the documented option signature.

Key points

  • The option is a callback that decides whether an arbitrary runtime value should count as an action creator.
  • Default detection targets standard Redux Toolkit action creators by requiring a function together with both static type and match members.
  • A custom predicate can deliberately broaden detection to every function carrying a static type property.
  • Configure the predicate by supplying it in the options passed to createActionCreatorInvariantMiddleware.
  • Most applications can rely on the middleware included by getDefaultMiddleware rather than constructing it directly.

Common mistakes

  • Pass the result of calling the action creator to dispatch; dispatching the function itself is the mistake this middleware is designed to detect.
  • A custom predicate can broaden or change detection, so ensure its criteria accurately identify the action creators used by the application.

Example: Custom action-creator predicate

import { configureStore, createActionCreatorInvariantMiddleware } from '@reduxjs/toolkit'
import reducer from './reducer'

const isActionCreator = (
  action: unknown,
): action is Function & { type: unknown } =>
  typeof action === 'function' && 'type' in action

const middleware = createActionCreatorInvariantMiddleware({ isActionCreator })

const store = configureStore({
  reducer,
  middleware: () => [middleware],
})

export default store

This custom predicate treats any function with a static type property as an action creator, allowing the invariant middleware to detect when such a function is dispatched without being called.

When to use it

Broaden middleware detection

An application uses action creators with a static type property but without the standard match method.

Support custom creator shapes

A project defines a custom action-creator convention that the default predicate does not recognize.

Catch dispatch mistakes

A team wants warnings when a creator function is dispatched directly instead of being invoked.

Interview questions

QWhat is isActionCreator?

isActionCreator is a predicate used by the action-creator invariant middleware to recognize values that represent action creators. Its return type is a TypeScript type predicate, narrowing a matching value to a function with an optional type property.

Follow-up: Why does the default recognize both type and match? Redux Toolkit action creators expose a static type string and a match() method, so checking both identifies the standard action-creator shape.

QWhat does the predicate inspect?

The function receives an unknown value and should return a boolean. The documented custom example identifies values that are functions and have a type property, returning true for those values.

Follow-up: How would you include creators without a type property? Change the predicate to test the actual distinguishing characteristic of those creators, while preserving a sound type predicate.

QHow is a custom predicate configured?

Pass the predicate through the isActionCreator option when creating action-creator invariant middleware. This is useful when the default recognition rules do not cover an application's action-creator conventions.

Follow-up: Is explicit middleware creation normally required? Usually not: getDefaultMiddleware already includes the action-creator check middleware.

  • createActionCreatorInvariantMiddleware
  • getDefaultMiddleware
  • createAction
  • createSlice

Source: Action Creator Middleware - Redux Toolkit. Checked 2026-10-15.