Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/components/menu/MenuModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const MenuModal = ({
originPrice: 0,
discountPrice: 0,
stock: 0,
productStatus: 'HIDDEN',
reservationStatus: 'PENDING',
productStatus: 'IN_STOCK',
reservationStatus: null,
tags: [],
});

Expand All @@ -81,8 +81,8 @@ const MenuModal = ({
originPrice: 0,
discountPrice: 0,
stock: 0,
productStatus: 'HIDDEN',
reservationStatus: 'PENDING',
productStatus: 'IN_STOCK',
reservationStatus: null,
Comment on lines +84 to +85

Choose a reason for hiding this comment

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

medium

이곳의 초기 메뉴 상태 객체는 상단의 useState 선언(55-64행)에 있는 객체와 동일합니다. 코드 중복을 피하고 향후 유지보수를 용이하게 하기 위해, 이 객체를 컴포넌트 외부의 상수로 추출하여 두 곳에서 모두 참조하도록 리팩터링하는 것을 고려해 보세요.

예시:

const initialMenuState = {
  image: null,
  name: '',
  originPrice: 0,
  discountPrice: 0,
  stock: 0,
  productStatus: 'IN_STOCK',
  reservationStatus: null,
  tags: [],
};

const MenuModal = ({...}) => {
  const [menu, setMenu] = useState(initialMenuState);

  useEffect(() => {
    if (initialData) {
      setMenu(initialData);
    } else {
      setMenu(initialMenuState);
    }
  }, [initialData]);
  // ...
}

tags: [],
});
}
Expand Down