From 9261ffe06388d5664de93b461fbba39d491f0d2c Mon Sep 17 00:00:00 2001 From: jason-zhu Date: Sun, 22 Oct 2023 00:33:57 +1100 Subject: [PATCH] Working on chap03 --- 02_lesson_starter/src/features/posts/postsSlice.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/02_lesson_starter/src/features/posts/postsSlice.js b/02_lesson_starter/src/features/posts/postsSlice.js index 7560cf0..2990bc4 100644 --- a/02_lesson_starter/src/features/posts/postsSlice.js +++ b/02_lesson_starter/src/features/posts/postsSlice.js @@ -19,6 +19,18 @@ export const fetchPosts = createAsyncThunk('posts/fetchPosts', async () => { } }); +export const addNewPost = createAsyncThunk( + 'posts/addNewPost', + async (initialPost) => { + try { + const response = await axios.post(POSTS_URL, initialPost); + return response.data; + } catch (err) { + return err.message; + } + } +); + const postsSlice = createSlice({ name: 'posts', initialState,