-
Notifications
You must be signed in to change notification settings - Fork 39
[전지윤] Sprint7 #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[전지윤] Sprint7 #218
The head ref may contain hidden characters: "React-\uC804\uC9C0\uC724-sprint7"
Conversation
GANGYIKIM
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지윤님 7번째 미션 수고하셨습니다!
지금 배포사이트에서 확인해보니 페이지에서 새로고침시 에러가 나고 있어요!
React는 SPA 방식이기 때문에 접근 주소에 해당하는 페이지가 없기 때문에 위와 같은 현상이 발생합니다. netfliy 문서를 확인해서 수정해보세요~
다음 미션도 화이팅입니다!
| <button | ||
| className={styles["back-button"]} | ||
| onClick={() => navigate("/items")} | ||
| > | ||
| 목록으로 돌아가기 | ||
| </button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💊 제안
지금 코드만으로 보면 버튼 태그보다 Link 태그를 쓰는게 더 적절해보여요.
단순 페이지 이동이 아니라 특정 로직을 실행해야한다면 지금처럼 버튼 태그를 사용하셔도 좋지만 아니라면 Link 태그로 변경해주세요~
링크 태그를 사용하시면 마우스 오른쪽 클릭이나 새탭 기능도 제공이 가능해서 UX 측면에서도 좋습니다.
| <textarea | ||
| className={styles["question__textarea"]} | ||
| id="comment" | ||
| value={message} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💊 제안
지금처럼 textarea 값을 useState로 제어하면 사용자가 입력할 때마다 컴포넌트가 리렌더링됩니다.
지금 코드상에서는 textarea 값을 바꿔주는 것이 아니라 제어 컴포넌트로 관리할 필요가 없을 것 같아요!
이를 비제어 컴포넌트로 바꾸셔서 불필요한 리렌더링을 줄이시는 것을 추천드려요!
| <button | ||
| className={`${styles["submit-button-none"]} ${ | ||
| message.trim() ? styles.active : "" | ||
| }`} | ||
| > | ||
| 등록 | ||
| </button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💊 제안
문의하기가 message 가 없을때 비활성화가 될 수 있게 해주세요~
또한 동적 class 를 활용하시기보다 css 가상클래스 :disabled를 통해 구현하시는 것이 더 적절할 것 같습니다.
| <button | |
| className={`${styles["submit-button-none"]} ${ | |
| message.trim() ? styles.active : "" | |
| }`} | |
| > | |
| 등록 | |
| </button> | |
| <button | |
| disabled={!!message.trim()} | |
| className={`${styles["submit-button-none"]}`} | |
| > | |
| 등록 | |
| </button> |
| </div> | ||
| </section> | ||
| <section className={styles["question"]}> | ||
| <form onSubmit={() => handleSubmit}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❗️ 수정요청
| <form onSubmit={() => handleSubmit}> | |
| <form onSubmit={handleSubmit}> |
| const [year, month, day] = createdAt.split("T")[0].split("-"); | ||
| const formattedDate = `${year}. ${month}. ${day}`; | ||
|
|
||
| async function handleSubmit(e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 여담
코멘트 등록까지 구조를 잡아두신 점 좋아요~
다만 로그인후 사용가능한 기능이라 추후 완성하시면 될 것 같습니다!
| import getComments from "../../API/getComments"; | ||
| import { useNavigate } from "react-router"; | ||
|
|
||
| export default function Product() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💊 제안
제 생각에는 아래처럼 비슷한 부분들을 모아두시는 것이 가독성 측면에서 더 좋을 것 같아요~
export default function Product() {
const [product, setProduct] = useState();
const [message, setMessage] = useState("");
const navigate = useNavigate();
const { productId } = useParams();
async function handleSubmit(e) { ... }
useEffect(() => { ...}, []);
if (!product) return <div>로딩 중...</div>;
return (...)
}|
|
||
| return ( | ||
| <div className={styles.item}> | ||
| <div className={styles.item} onClick={onClick}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❗️ 수정요청
해당 컴포넌트 클릭시 해당 요소의 상세 페이지로 이동이니 Link 태그가 적절할 것 같아요!
| return ( | ||
| <> | ||
| {isEmpty ? ( | ||
| <div className={styles.isEmpty}> | ||
| <img src={empty} alt="comment empty" /> | ||
| <p>아직 문의가 없어요</p> | ||
| </div> | ||
| ) : ( | ||
| <div className={styles["comment-content"]}> | ||
| {comments.map((comment) => ( | ||
| <Comment | ||
| comment={comment} | ||
| handleModify={handleModify} | ||
| handleDelete={handleDelete} | ||
| /> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </> | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💊 제안
이런 경우 React fragment로 감싸지 않으시고 조건부 렌더링을 바로 하시면 됩니다~
| return ( | |
| <> | |
| {isEmpty ? ( | |
| <div className={styles.isEmpty}> | |
| <img src={empty} alt="comment empty" /> | |
| <p>아직 문의가 없어요</p> | |
| </div> | |
| ) : ( | |
| <div className={styles["comment-content"]}> | |
| {comments.map((comment) => ( | |
| <Comment | |
| comment={comment} | |
| handleModify={handleModify} | |
| handleDelete={handleDelete} | |
| /> | |
| ))} | |
| </div> | |
| )} | |
| </> | |
| ); | |
| return { isEmpty ? ( | |
| <div className={styles.isEmpty}> | |
| <img src={empty} alt="comment empty" /> | |
| <p>아직 문의가 없어요</p> | |
| </div> | |
| ) : ( | |
| <div className={styles["comment-content"]}> | |
| {comments.map((comment) => ( | |
| <Comment | |
| comment={comment} | |
| handleModify={handleModify} | |
| handleDelete={handleDelete} | |
| /> | |
| ))} | |
| </div> | |
| )}; |
| useEffect(() => { | ||
| async function fetchComments() { | ||
| try { | ||
| const comments = await getComments(productIdNum, 3, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❗️ 수정요청
지금은 고정값으로 코멘트를 불러오고 있어요~
모든 코멘트가 보이도록 무한스크롤 방식으로 구현해주시면 좋겠습니다!
| import { useState } from "react"; | ||
| export default function Comment({ comment, handleModify, handleDelete }) { | ||
| const { content, updatedAt, id, writer } = comment; | ||
| const [show, setShow] = useState(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 여담
reducer 를 사용해 아래처럼 간단하게도 작성 가능합니다~
| const [show, setShow] = useState(false); | |
| const [isShow, toggleIsShow] = useReducer((prev) => !prev, false); |
요구사항
배포 링크
https://react-15-7.netlify.app/
기본
상품 상세
상품 문의 댓글
심화
스크린샷
데스크탑
태블릿
모바일
등록 버튼 활성화, 코멘트 수정/삭제 폼
멘토에게