From 91bade933666013530648d23b16001cfe00d3a3c Mon Sep 17 00:00:00 2001 From: Matthias Nagel Date: Tue, 29 Oct 2024 23:16:51 +0100 Subject: [PATCH 1/2] Update part-5-async-logic.md Fixed some typos and highlighting --- docs/tutorials/essentials/part-5-async-logic.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/tutorials/essentials/part-5-async-logic.md b/docs/tutorials/essentials/part-5-async-logic.md index 8e841ba64f..905c15d1ea 100644 --- a/docs/tutorials/essentials/part-5-async-logic.md +++ b/docs/tutorials/essentials/part-5-async-logic.md @@ -307,7 +307,7 @@ We _could_ track that information using some booleans, like `isLoading: true`, b ```ts { // Multiple possible status enum values - status: 'idle' | 'pending' | 'succeeded' | 'failed', + status: 'idle' | 'pending' | 'succeeded' | 'rejected', error: string | null } ``` @@ -508,7 +508,7 @@ const postsSlice = createSlice({ state.posts.push(...action.payload) }) .addCase(fetchPosts.rejected, (state, action) => { - state.status = 'failed' + state.status = 'rejected' state.error = action.error.message ?? 'Unknown Error' }) // highlight-end @@ -520,7 +520,7 @@ We'll handle all three action types that could be dispatched by the thunk, based - When the request starts, we'll set the `status` enum to `'pending'` - If the request succeeds, we mark the `status` as `'succeeded'`, and add the fetched posts to `state.posts` -- If the request fails, we'll mark the `status` as `'failed'`, and save any error message into the state so we can display it +- If the request fails, we'll mark the `status` as `'rejected'`, and save any error message into the state so we can display it ### Dispatching Thunks from Components @@ -1026,6 +1026,12 @@ const postsSlice = createSlice({ // highlight-end } }) + +// highlight-start +// Remove `postAdded` +export const { postUpdated, reactionAdded } = postsSlice.actions +// highlight-end + ``` ### Checking Thunk Results in Components @@ -1052,10 +1058,11 @@ import { addNewPost } from './postsSlice' // omit field types export const AddPostForm = () => { - // highlight-next-line + // highlight-start const [addRequestStatus, setAddRequestStatus] = useState<'idle' | 'pending'>( 'idle' ) + // highlight-end const dispatch = useAppDispatch() const userId = useAppSelector(selectCurrentUsername)! From 53f2d0bc153bd56cdc917754debac9cd0d9a975c Mon Sep 17 00:00:00 2001 From: Matthias Nagel Date: Wed, 30 Oct 2024 08:09:08 +0100 Subject: [PATCH 2/2] Update part-5-async-logic.md Changed failed status in PostsState to failed --- docs/tutorials/essentials/part-5-async-logic.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/tutorials/essentials/part-5-async-logic.md b/docs/tutorials/essentials/part-5-async-logic.md index 905c15d1ea..957a4afca7 100644 --- a/docs/tutorials/essentials/part-5-async-logic.md +++ b/docs/tutorials/essentials/part-5-async-logic.md @@ -307,7 +307,7 @@ We _could_ track that information using some booleans, like `isLoading: true`, b ```ts { // Multiple possible status enum values - status: 'idle' | 'pending' | 'succeeded' | 'rejected', + status: 'idle' | 'pending' | 'succeeded' | 'failed', error: string | null } ``` @@ -326,7 +326,7 @@ import { createSlice, nanoid } from '@reduxjs/toolkit' // highlight-start interface PostsState { posts: Post[] - status: 'idle' | 'pending' | 'succeeded' | 'rejected' + status: 'idle' | 'pending' | 'succeeded' | 'failed' error: string | null } @@ -508,7 +508,7 @@ const postsSlice = createSlice({ state.posts.push(...action.payload) }) .addCase(fetchPosts.rejected, (state, action) => { - state.status = 'rejected' + state.status = 'failed' state.error = action.error.message ?? 'Unknown Error' }) // highlight-end @@ -520,7 +520,7 @@ We'll handle all three action types that could be dispatched by the thunk, based - When the request starts, we'll set the `status` enum to `'pending'` - If the request succeeds, we mark the `status` as `'succeeded'`, and add the fetched posts to `state.posts` -- If the request fails, we'll mark the `status` as `'rejected'`, and save any error message into the state so we can display it +- If the request fails, we'll mark the `status` as `'failed'`, and save any error message into the state so we can display it ### Dispatching Thunks from Components