// 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 = {};
});
},
});
获得视频后如何分派另一个异步函数依次运行 2 分派一个接一个。第二个取决于第一个。
当我运行 node index.js 时,它应该按顺序运行 2 dispatch。但是怎么办?没有反应。就在节点应用上
我正在尝试使用中间件。但不工作
// Subscribe to state changes
store.subscribe(() => {});
store.dispatch(fetchVideo());
那么,现在如何立即派发第二个动作,第一个动作已满。