Inflearn Community Q&A
불변성 유지하면서 변수 만들 때 질문이 있습니다.
Written on
·
304
0
불변성 유지하기 위해서 변수 만들떄
const postIndex = state.mainPosts.findIndex((v) => v.id === action.data.postId);
const post = {...state.mainPosts[postIndex]}
post.Comments = [dummyComments(action.data.content), ...post.Comments]
const mainPosts = [...state.mainPosts]
mainPosts[postIndex] = post
이러한 과정을 거치던데
const post = {...state.mainPosts[postIndex]}
부분이 왜 {}로 감싸져 있는걸까요??
대괄호인 []로 감싸져야 하는게 아닐까요??
그 아래인 const mainPosts = [...state.mainPosts]로 []로 감싸져 있는데 왜그런걸까요
reactreduxexpressnodejsNext.js





아~ 그렇군요 이해했습니다^^