From 573491db427848fc611eafa3048990775214d4ad Mon Sep 17 00:00:00 2001 From: gitdagray Date: Sat, 8 Oct 2022 13:40:53 -0500 Subject: [PATCH] Fix for new post ids after entity adapter is added --- 05_lesson/src/features/posts/postsSlice.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/05_lesson/src/features/posts/postsSlice.js b/05_lesson/src/features/posts/postsSlice.js index a72f6b3..05f5f60 100644 --- a/05_lesson/src/features/posts/postsSlice.js +++ b/05_lesson/src/features/posts/postsSlice.js @@ -99,12 +99,8 @@ const postsSlice = createSlice({ // Creating sortedPosts & assigning the id // would be not be needed if the fake API // returned accurate new post IDs - const sortedPosts = state.posts.sort((a, b) => { - if (a.id > b.id) return 1 - if (a.id < b.id) return -1 - return 0 - }) - action.payload.id = sortedPosts[sortedPosts.length - 1].id + 1; + + action.payload.id = state.ids[state.ids.length - 1] + 1 // End fix for fake API post IDs action.payload.userId = Number(action.payload.userId)