0
// Create async thunk to get random video
const fetchVideo = createAsyncThunk('video/fetchVideo', async () => {
    const response = await fetch('http://localhost:9000/video');
    const video = await response.json();

    return video;
});

// Create slice
const videosSlice = createSlice({
    name: 'videos',
    initialState,
    extraReducers: (builder) => {
        builder
            .addCase(fetchVideo.pending, (state) => {
                state.isLoading = true;
                state.isError = false;
                state.error = '';
            })
            .addCase(fetchVideo.fulfilled, (state, action) => {
                state.isLoading = false;
                state.isError = false;
                state.error = '';
                state.video = action.payload;
            })
            .addCase(fetchVideo.rejected, (state, action) => {
                state.isLoading = fetch;
                state.isError = true;
                state.error = action.error?.message;
                state.video = {};
            });
    },
});

After get a video how to dispatch another async function sequentially run 2 dispatch one after one. second one depnend on the 1st one.

When I run node index.js it should run 2 dispatch sequentially. But how? with out react. Just on node app

I was trying to using middlware. but not working

// Subscribe to state changes
store.subscribe(() => {});

store.dispatch(fetchVideo());

So, now how to dispatch 2nd action instandly 1st one fullfilled.

Wyarej Ali
  • 11
  • 2

0 Answers0