Skip to main content

[ ![Redux Logo](/img/redux.svg) ![Redux Logo](/img/redux.svg) **Redux
Toolkit** ](/)

[ Getting Started ](/introduction/getting-started) [ Tutorials
](/tutorials/overview) [ Usage Guide ](/usage/usage-guide) [ API
](/api/configureStore) [ RTK Query ](/rtk-query/overview) [ GitHub
](https://github.com/reduxjs/redux-toolkit)

Search

  * [ Introduction ](/introduction/getting-started)

    * [ Getting Started ](/introduction/getting-started)
    * [ Why Redux Toolkit is How To Use Redux Today ](/introduction/why-rtk-is-redux-today)
  * [ Tutorials ](/tutorials/overview)

    * [ Tutorials Overview ](/tutorials/overview)
    * [ Quick Start ](/tutorials/quick-start)
    * [ TypeScript Quick Start ](/tutorials/typescript)
    * [ RTK Query Quick Start ](/tutorials/rtk-query)
  * [ Using Redux Toolkit ](/usage/migrating-to-modern-redux)

    * [ Migrations ](/usage/migrating-to-modern-redux)

    * [ Usage Guide ](/usage/usage-guide)
    * [ Usage With TypeScript ](/usage/usage-with-typescript)
    * [ Writing Reducers with Immer ](/usage/immer-reducers)
    * [ Setup with Next.js ](/usage/nextjs)
  * [ API Reference ](/api/configureStore)

    * [ Store Setup ](/api/configureStore)

      * [ configureStore ](/api/configureStore)
      * [ getDefaultMiddleware ](/api/getDefaultMiddleware)
      * [ Immutability Middleware ](/api/immutabilityMiddleware)
      * [ Serializability Middleware ](/api/serializabilityMiddleware)
      * [ Action Creator Middleware ](/api/actionCreatorMiddleware)
      * [ createListenerMiddleware ](/api/createListenerMiddleware)
      * [ createDynamicMiddleware ](/api/createDynamicMiddleware)
      * [ getDefaultEnhancers ](/api/getDefaultEnhancers)
      * [ autoBatchEnhancer ](/api/autoBatchEnhancer)
    * [ Reducers and Actions ](/api/createReducer)

      * [ createReducer ](/api/createReducer)
      * [ createAction ](/api/createAction)
      * [ createSlice ](/api/createSlice)
      * [ createAsyncThunk ](/api/createAsyncThunk)
      * [ createEntityAdapter ](/api/createEntityAdapter)
      * [ combineSlices ](/api/combineSlices)
    * [ Other ](/api/createSelector)

      * [ createSelector ](/api/createSelector)
      * [ Matching Utilities ](/api/matching-utilities)
      * [ Other Exports ](/api/other-exports)
      * [ Codemods ](/api/codemods)
      * [ Error Messages ](/errors)
  * [ RTK Query ](/rtk-query/overview)

    * [ RTK Query Overview ](/rtk-query/overview)
    * [ Comparison with Other Tools ](/rtk-query/comparison)
    * [ Examples ](/rtk-query/usage/examples)
    * [ Usage With TypeScript ](/rtk-query/usage-with-typescript)
    * [ Using RTK Query ](/rtk-query/usage/queries)

    * [ API Reference ](/rtk-query/api/createApi)

  * [ ](/)
  * API Reference 
  * Reducers and Actions 
  * createAction 

On this page

#  ` createAction `

A helper function for defining a Redux [ action
](https://redux.js.org/basics/actions) type and creator.

    
    
    function createAction(type, prepareAction?)  
    

The usual way to define an action in Redux is to separately declare an _action
type_ constant and an _action creator_ function for constructing actions of
that type.

  * TypeScript 
  * JavaScript 

    
    
    const INCREMENT = 'counter/increment'  
      
    function increment(amount: number) {  
      return {  
        type: INCREMENT,  
        payload: amount,  
      }  
    }  
      
    const action = increment(3)  
    // { type: 'counter/increment', payload: 3 }  
    
    
    
    const INCREMENT = 'counter/increment'  
      
    function increment(amount) {  
      return {  
        type: INCREMENT,  
        payload: amount,  
      }  
    }  
      
    const action = increment(3)  
    // { type: 'counter/increment', payload: 3 }  
    

The ` createAction ` helper combines these two declarations into one. It takes
an action type and returns an action creator for that type. The action creator
can be called either without arguments or