(PostCard.js)
/* onClick -> 댓글창 열고닫기 */
const onToggleComment = useCallback(() => {
console.log(commentFormOpened); // false
setCommentFormOpened(prev => !prev);
console.log(commentFormOpened); // false //
console.log(commentFormOpened);
if (!commentFormOpened) {
dispatch({
type: LOAD_COMMENTS_REQUEST,
data: post.id,
});
}
}, [commentFormOpened]);
여기서, setCommentFormOpened()를 했을때, commentFormOpened state가 즉시 true로 변하지 않는 이유가 무엇인가요 ?
console.log를 찍어보니 setCommentFormOpened() 앞뒤로 둘다 false가 떠서 궁금해서 질문드립니다.