Refactoring Tweetfind to Use createAsyncThunk
Learn to use the createAsyncThunk utility function in a practical way.
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 = error.toString();
...