Fix for new post ids after entity adapter is added

02_lesson
gitdagray 2022-10-08 13:40:53 -05:00
parent 4c4fe735c1
commit 573491db42
1 changed files with 2 additions and 6 deletions

View File

@ -99,12 +99,8 @@ const postsSlice = createSlice({
// Creating sortedPosts & assigning the id // Creating sortedPosts & assigning the id
// would be not be needed if the fake API // would be not be needed if the fake API
// returned accurate new post IDs // returned accurate new post IDs
const sortedPosts = state.posts.sort((a, b) => {
if (a.id > b.id) return 1 action.payload.id = state.ids[state.ids.length - 1] + 1
if (a.id < b.id) return -1
return 0
})
action.payload.id = sortedPosts[sortedPosts.length - 1].id + 1;
// End fix for fake API post IDs // End fix for fake API post IDs
action.payload.userId = Number(action.payload.userId) action.payload.userId = Number(action.payload.userId)