Skip to content
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

[김정현] Sprint6 #183

Conversation

kjh9852
Copy link
Collaborator

@kjh9852 kjh9852 commented Jun 28, 2024

요구사항

기본

배포링크 입니당

  • Github에 PR(Pull Request)을 만들어서 미션을 제출합니다.
  • 피그마 디자인에 맞게 페이지를 만들어 주세요.
  • React를 사용합니다
  • 상품 등록 페이지 주소는 “/additem” 입니다.
  • 페이지 주소가 “/additem” 일때 상단네비게이션바의 '중고마켓' 버튼의 색상은 “3692FF”입니다.
  • 상품 이미지는 최대 한개 업로드가 가능합니다.
  • 각 input의 placeholder 값을 정확히 입력해주세요.
  • 이미지를 제외하고 input 에 모든 값을 입력하면 ‘등록' 버튼이 활성화 됩니다.
  • API를 통한 상품 등록은 추후 미션에서 적용합니다.

심화

  • 이미지 안의 X 버튼을 누르면 이미지가 삭제됩니다.
  • 추가된 태그 안의 X 버튼을 누르면 해당 태그는 삭제됩니다.

주요 변경사항

  • 이전 미션 코드 리뷰 반영해보았습니다.
  • 로딩 UI 컴포넌트 제작 해보았습니다
  • 이미지 대신 CSS 가상요소로 대체 할 수 있는 요소들은 가상요소로 만들었습니다

스크린샷

screencapture-localhost-3000-additem-2024-06-28-22_33_12

멘토에게

  • 임시로 firebase로 POST를 테스트 해보려고 코드를 짜봤는데 realdatabase에서는 이미지 파일이 안 올라간다는 걸 알고 삽질 한 것 같습니다.
  • input들의 value 값을 하나의 state에 넣어서 관리를 하게 되는데 input 하나가 바뀔 때 마다 모든 input이 재랜더링 되는 것 같은데 하나 하나 구분하는게 좋을까요?
  • 셀프 코드 리뷰를 통해 질문 이어가겠습니다.

@kjh9852 kjh9852 requested a review from JaeSang1998 June 28, 2024 13:46
@kjh9852 kjh9852 added the 매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다. label Jun 28, 2024
@kjh9852 kjh9852 self-assigned this Jun 28, 2024
Copy link
Collaborator

@JaeSang1998 JaeSang1998 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정현님 너무 고생하셨습니다~!

};

const loadedItem = async () => {
const loadedItem = useCallback(async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadedItem 처럼 계산된 결과값 안에서 값을 불러오고 싶으면 useCallback 보다 useMemo 를 쓰는게 더 좋아보입니다.

이 부분이 함수라면 동사로 시작하는것이 좋아보여요 :) loadItems 처럼요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadedItem 처럼 계산된 결과값 안에서 값을 불러오고 싶으면 useCallback 보다 useMemo 를 쓰는게 더 좋아보입니다.

이 부분이 함수라면 동사로 시작하는것이 좋아보여요 :) loadItems 처럼요

loadedItem가 함수라서 useCallback을 사용했는데 useMemo 사용이 되나용??

useEffect(() => {
const { title, description, price, tag } = formValues;
setIsActive(() => {
const active =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 active 계산은 setIsActive 함수 밖에서 사용되어서 넘겨주었어도 좋았을 것 같아요. 들여쓰기가 추가되어서 가독성이 조금 떨어져 보입니다


const handleAddTags = e => {
let { value } = e.target;
if (e.key === 'Enter' && tagValue !== '') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 if 문 들여쓰기가 많을때에는 guard clause 패턴을 써보면 좋아요.
쉽게 말해서 if(true) return; early return 을 통해서 불필요한 조건에서 먼저 탈출하는거죠!

let { value } = e.target;
if (e.key === 'Enter' && tagValue !== '') {
const existingTag =
tags && tags.some(tag => tag.name === tagValue.trim());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some 👍


const getLocationActive = ({ isActive, to }) => {
if (
(location.pathname === "/items" || location.pathname === "/additem") &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 문 안에 조건이 복잡하게 들어가있어요 이럴때는 위에서 isActive 로 표현해줬던 것 처럼 명확하게 변수로 이름지어 표현해주면 좋을 것 같아요!

};

useEffect(() => {
if (location.pathname === "/additem") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 경우에는 setTempLogin(location.pathname === '/additem') 과 같은 코드입니다 :)

import Section from '../../ui/Section/Section.jsx';
import Loading from '../../ui/Loading/Loading.jsx';
import styles from './AllProduct.module.css';

const deviceSize = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 상수로 사용하는 습관 매우 좋습니다!

상수표기는 DEVICE_SIZE 의 형태로 많이 쓰이니 참고해보셔도 좋을 것 같아요 !

@@ -29,10 +30,10 @@ export default function AllProduct() {
const [loading, setLoading] = useState(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

페이지네이션과 한번에 컴포넌트를 사용하게 되면서 state 를 9개나 사용하게 되었어요. itemList 불러오는 로직, pagination 을 구성하는 로직을 분리해보면 좋을것 같습니다

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 불필요한 state 를 없애고, 만약 AllProduct 에서 계산할 필요가 없는 state ex) maxPage 같은 것들은 하단 Pagination 컴포넌트 안으로 밀어넣어서 state 를 줄이면 좋을 것 같음
  2. keyword, order option 을 하나의 객체로 만들어서 변경하도록 하면 state 를 줄일 수 있게 되고

  1. custom hook 같은것들을 사용하면. (hook 함수 분리) is Loading error 데이터를 보여주는 layer의 state 들을 하나로 합쳐지도록 보이게 할 수 있어요.

@JaeSang1998 JaeSang1998 merged commit be3c3c8 into codeit-bootcamp-frontend:React-김정현 Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants