I am trying to use redux-toolkit to store data from an api.I tried it but I am getting this error saying "The object notation for createSlice.extraReducers
has been removed. Please use the 'builder callback' notation instead" Here's the code snippet:
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
export const getAllJobs=createAsyncThunk("jobDetails",async ()=>{
const data = await fetch(" http://localhost:3031/jobs");
const result = data.json();
return result
})
export const jobDetails=createSlice({
name:"jobDetails",
initialState:{
jobs:[],
loading:false,
error:null,
},
extraReducers:{
[getAllJobs.pending]: (state)=>{
state.loading=true;
},
[getAllJobs.fulfilled]: (state,action)=>{
state.loading=false;
state.jobs=action.payload;
},
[getAllJobs.rejected]: (state,action)=>{
state.loading=false;
state.error=action.payload;
},
},
})
export default jobDetails.reducer;
and for store
import {configureStore} from '@reduxjs/toolkit'
import jobDetails from '../features/jobSlice'
export const store= configureStore({
reducer: {
app: jobDetails
},
})
I am trying to store fetched api data to jobs