1 year ago

#76761

test-img

DevGe

How to globally use the created redux slice using redux toolkit?

I have question and I really don't know what proper term for this. My question is how to call created slice from another slice?

Goal: To re initial state the notification data from the other page.

Here is my testing Process (But it won't work):

  1. Import the DashboardThunk to the ActivityLogSlice and then call it to the fulfilled. Badly the DashboardThunk is not running and not re initialize the state.

Here is my code:

My DashboardSlice:

export const DashboardThunk = createAsyncThunk(
'admin/dashboard',
async (_, {rejectWithValue, dispatch}) => {
  try {
    const {data} = await api.get('/admin/dashboard');
    return data;
  } catch (err) {
    if (!err.response) {
      throw err
    }
  }
}

Here is my ActivityLogSlice:

import {DashboardThunk} from './DashboardSlice'

export const ActivityLogSlice = createSlice({
name:"activity_log",
initialState: InitialState,
extraReducers: (builder) => {

    builder.addCase(ActivityLog.pending, (state, action) => {
        state.isLoading = true
    })
    builder.addCase(ActivityLog.fulfilled, (state, action) => {
        state.isLoading = false
        state.logs = action.payload
        DashboardThunk()
    })
    builder.addCase(ActivityLog.rejected, (state, action) => {
        state.isLoading = false
    })

}

reactjs

redux

redux-toolkit

0 Answers

Your Answer

Accepted video resources