오늘까지 반영사항은 깃허브 finalProject에 merge함
{post.myPost === true ?(<>
<img
className="h-[18px] w-[18px] absolute right-4"
src={blueToggle}
onClick={editToggleHandler}
/>
</>) : ""}
(부분 코드)
(PostList.jsx)
{posts.length > 0 &&
// 전체 조건부 렌더링
posts.map((post, index) => {
return (
<div
className="bg-white flex p-[18px] border-b-[0.5px] border-D9"
key={index}
onClick={() => {
onClickHandler(post.postId);
}}
>
<img
className="object-cover min-w-[84px] w-[84px] h-[84px] rounded"
src={post?.images[0]?.imgUrl}
/>
// 요소별 옵셔널 체이닝
<div className=" w-full flex-col ml-3 font-medium">
<div>
<label>{post?.title}</label>
</div>
<div className=" mt-1 text-base font-semibold">
<label>{post?.userPrice.toLocaleString("ko-KR")}원</label>
</div>
<div className="flex justify-between mt-4 text-xs font-normal">
<div>{post?.createdAt}</div>
<div className="flex">
<img src={mainHeart} />
<div>{post?.likeCnt}</div>
</div>
</div>
</div>
</div>
);
})}
(PostsSlice.js)
//__addPost
[__addPost.pending]: (state) => {
state.isLoading = true;
},
[__addPost.fulfilled]: (state, action) => {
state.isLoading = false;
state.posts.push(action.payload);
window.location.replace("/postread/all")
// replace 활용한 새로고침 및 렌더링
},
[__addPost.rejected]: (state, action) => {
state.isLoading = false;
state.error = action.payload;
},