How to fix createAsyncThunk requires a string action type and a payloadCreator function in React

ReactBEGINNERMEDIUMUpdated Dec 10, 2025ยท 101 views

This error occurs when using Redux Toolkit's createAsyncThunk function with incorrect arguments. The createAsyncThunk API requires exactly two arguments: a string action type prefix and a payload creator function that returns a promise.

Quick fix

Fixes createAsyncThunk requires a string action type and a payloadCreator function

import { createAsyncThunk } from '@reduxjs/toolkit';

// Correct syntax:
const fetchUserById = createAsyncThunk(
  'users/fetchById', // 1st arg: string action type prefix
  async (userId, thunkAPI) => { // 2nd arg: payload creator function
    const response = await fetch(`/api/users/${userId}`);
    return await response.json();
  }
);
  1. Verify the basic createAsyncThunk syntax
  2. Check the action type prefix is a string
  3. Ensure the payload creator is a function
  4. Review imports and package version
react โ€” error
import { createAsyncThunk } from '@reduxjs/toolkit';
// Correct syntax:
const fetchUserById = createAsyncThunk(
'users/fetchById', // 1st arg: string action type prefix
async (userId, thunkAPI) => { // 2nd arg: payload creator function
const response = await fetch(`/api/users/${userId}`);
return await response.json();
}
);
createAsyncThunk requires a string action type and a payloadCreator function

What this error means

The createAsyncThunk function from Redux Toolkit is a utility for creating Redux thunks that handle asynchronous operations like API calls. It generates three action types automatically (pending, fulfilled, rejected) based on the string prefix you provide. The function expects two mandatory arguments: 1) a string action type prefix (e.g., "users/fetchById"), and 2) a payload creator function that returns a promise. When you call createAsyncThunk with incorrect argument types or missing arguments, Redux Toolkit throws this error to indicate the API contract has been violated.

Typical symptoms

  • Redux thunk creation fails during development
  • Console shows error: "createAsyncThunk requires a string action type and a payloadCreator function"
  • Application crashes when trying to create an async thunk
  • TypeScript may show type errors if using incorrect argument types
  • Redux DevTools shows no async actions being dispatched

Common causes

  1. Passing a non-string value as the first argument (action type prefix)
  2. Forgetting to provide the payload creator function as the second argument
  3. Passing undefined or null as either argument
  4. Providing additional arguments beyond the two required ones
  5. Using an object or array instead of a string for the action type prefix
  6. Passing the payload creator function as the first argument instead of the second
  7. Importing createAsyncThunk incorrectly or from the wrong package

How to fix "createAsyncThunk requires a string action type and a payloadCreator function"

1Verify the basic createAsyncThunk syntax

Ensure you are calling createAsyncThunk with exactly two arguments in the correct order:

javascript
import { createAsyncThunk } from '@reduxjs/toolkit';

// Correct syntax:
const fetchUserById = createAsyncThunk(
  'users/fetchById', // 1st arg: string action type prefix
  async (userId, thunkAPI) => { // 2nd arg: payload creator function
    const response = await fetch(`/api/users/${userId}`);
    return await response.json();
  }
);
2Check the action type prefix is a string

The first argument must be a string literal or string variable:

javascript
// Correct - string literal
const fetchUser = createAsyncThunk('users/fetch', async () => { /* ... */ });

// Correct - string variable
const actionPrefix = 'users/fetch';
const fetchUser = createAsyncThunk(actionPrefix, async () => { /* ... */ });

// INCORRECT - number, object, array, etc.
const fetchUser = createAsyncThunk(123, async () => { /* ... */ }); // Error
const fetchUser = createAsyncThunk({ type: 'users/fetch' }, async () => { /* ... */ }); // Error
3Ensure the payload creator is a function

The second argument must be a function that returns a promise:

javascript
// Correct - async function
const fetchUser = createAsyncThunk('users/fetch', async (userId) => {
  const response = await fetch(`/api/users/${userId}`);
  return response.json();
});

// Correct - function returning a promise
const fetchUser = createAsyncThunk('users/fetch', (userId) => {
  return fetch(`/api/users/${userId}`).then(response => response.json());
});

// INCORRECT - not a function
const fetchUser = createAsyncThunk('users/fetch', fetch(`/api/users/1`)); // Error
const fetchUser = createAsyncThunk('users/fetch', null); // Error
const fetchUser = createAsyncThunk('users/fetch'); // Error - missing second arg
4Review imports and package version

Make sure you are importing createAsyncThunk correctly from Redux Toolkit:

javascript
// Correct import for Redux Toolkit
import { createAsyncThunk } from '@reduxjs/toolkit';

// Not from 'redux' or 'redux-thunk' packages

Check your package.json to ensure @reduxjs/toolkit is installed and at a compatible version (1.5.0+ for createAsyncThunk).

5Examine TypeScript types if applicable

If using TypeScript, ensure you provide proper type annotations:

typescript
import { createAsyncThunk } from '@reduxjs/toolkit';
import type { AppDispatch, RootState } from './store';

interface User {
  id: number;
  name: string;
}

// With TypeScript types
const fetchUserById = createAsyncThunk<User, number, {
  dispatch: AppDispatch;
  state: RootState;
}>(
  'users/fetchById',
  async (userId, thunkAPI) => {
    const response = await fetch(`/api/users/${userId}`);
    return await response.json() as User;
  }
);

Make sure type arguments match the function signature.

6Test with a minimal example

Create a minimal async thunk to isolate the issue:

javascript
import { createAsyncThunk } from '@reduxjs/toolkit';

// Minimal working example
const testThunk = createAsyncThunk(
  'test/action',
  async () => {
    return 'test data';
  }
);

console.log(testThunk.pending('requestId')); // Should log pending action
console.log(testThunk.fulfilled('result', 'requestId')); // Should log fulfilled action

If this works, compare with your original code to find differences.

Advanced notes

The createAsyncThunk function internally creates three action creators: pending, fulfilled, and rejected. The string prefix you provide is used to generate these action types (e.g., "users/fetchById/pending"). The payload creator function receives two arguments: 1) the first argument passed when dispatching the thunk, and 2) a thunkAPI object containing { dispatch, getState, extra, requestId, signal }. For advanced use cases, you can pass an options object as a third argument to configure the thunk behavior, but this is optional. Common options include condition (to skip execution) and dispatchConditionRejection.

Frequently asked questions

What does "createAsyncThunk requires a string action type and a payloadCreator fu" mean?
The createAsyncThunk function from Redux Toolkit is a utility for creating Redux thunks that handle asynchronous operations like API calls. It generates three action types automatically (pending, fulfilled, rejected) based on the string prefix you provide. , "users/fetchById"), and 2) a payload creator function that returns a promise.
How do I fix "createAsyncThunk requires a string action type and a payloadCreator fu"?
This error occurs when using Redux Toolkit's createAsyncThunk function with incorrect arguments. The createAsyncThunk API requires exactly two arguments: a string action type prefix and a payload creator function that returns a promise.
What causes "createAsyncThunk requires a string action type and a payloadCreator fu"?
Passing a non-string value as the first argument (action type prefix) Forgetting to provide the payload creator function as the second argument Passing undefined or null as either argument
Is the "createAsyncThunk requires a string action type and a payloadCreator fu" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading