Feed UI를 만들고자 한다.
instagram에서 메인이 되는 페이지이다.(home)
여러개 post를 map 하여 보여준다.
seeFeed.map((post) => <Post key={post.id} id={post.id} ... />
presenter component와 container component를 나눠서 작성하는 패턴으로 한 component에 모두 넣기에는 너무 커질 때 presenter영역과 container(logic)영역을 별도로 나눠서 프로그래밍하는 패턴이다.
state 관리 useEffect를 통한 반응형 component관리
onKeyDown
or onKeyPress
) submit 되도록 이벤트 처리const onKeyPress = async (e) => {
const { keyCode } = e;
if (keyCode === 13) {
e.preventDefault();
try {
const {
data: { addComment },
} = await addCommentMutation();
setSelfComment([...selfComment, addComment]);
comment.setValue("");
} catch {
toast.error("Can't send comment");
}
}
return;
};
export const ADD_COMMENT = gql`
mutation addComment($postId: String!, $text: String!) {
addComment(postId: $postId, text: $text) {
id
text
user {
username
}
}
}
`;