Refactoring Tweetfind to Use createAsyncThunk
Explore refactoring async Redux operations using createAsyncThunk in Redux Toolkit to simplify your code. Understand replacing manual thunks, updating slices with extraReducers, and passing parameters as objects. This lesson helps you streamline async logic in your Twitter search app.
We'll cover the following...
We'll cover the following...
Practical createAsyncThunk
We’ve talked a lot about createAsyncThunk, but talk is cheap.
Update the manually created thunk to use createAsyncThunk:
// finderSlice.js
// before
export const fetchTweets = (searchValue, numberOfResults) => async (
dispatch
) => {
try {
dispatch(isLoadingTweets());
const tweets = await findTweets(searchValue, numberOfResults);
dispatch(loadingTweetsSuccess(tweets));
} catch (error) {
const errorMsg = ...