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

export const fetchUserData = createAsyncThunk(
  'user/fetchData',
  async (userId, thunkAPI) => {
    const response = await fetch(`https://jsonplaceholder.typicode.com/users/${userId}`);
    const data = await response.json();

    // Dispatch multiple actions
    thunkAPI.dispatch(actions.setUserName(data.name));
    thunkAPI.dispatch(actions.setUserEmail(data.email));

    return data;
  }
);
Tagged: Redux

Leave a comment

Your email address will not be published. Required fields are marked *