createAction Function

Deprecated  in 4.15.0. Use your state management types instead, i.e. createAction from @reduxjs/toolkit instead.

Creates a basic Redux Redux Action without a payload. This is meant to be used as a shortcut for defining Action Creators.

For example,

  () => createAction("FOO", ids)

defines an action creator of type:

  () => { type: "FOO" }
  // which is equivalent to:
  () => Action<"FOO">

Note that the generic type parameters can always be omitted - TypeScript will be able to infer them.

createAction<T extends string>(type: T): Action<T>

Parameter Type Description
type T The string to use as the action's type property. Should have a string literal type.

Returns - Action<T>

Creates a basic Redux Redux Action with a payload value. This is meant to be used as a shortcut for defining Action Creators.

For example,

  (ids: number[]) => createAction("FOO", ids)

defines an action creator of type:

  (ids: number[]) => { type: "FOO", payload: ReadonlyArray<number> }
  // which is equivalent to:
  (ids: number[]) => ActionWithPayload<"FOO", ReadonlyArray<number>>

Note that the generic type parameters can always be omitted - TypeScript will be able to infer them.

createAction<T extends string, P>(type: T, payload: P): ActionWithPayload<T, DeepReadonly<P>>

Parameter Type Description
type T The string to use as the action's type property. Should have a string literal type.
payload P The value to use as the action's payload property. May be of any type.

Returns - ActionWithPayload<T, DeepReadonly<P>>

Defined in

Last Updated: 17 December, 2024