Skip to content

Conversation

@maclovedany
Copy link
Collaborator

요구사항

기본

  • 네모 박스 안의 화면을 TypeScript로 마이그레이션해 주세요.

심화

  • any타입을 최소한으로 써주세요

주요 변경사항

  • homepage, signinpage, signuppage 를 typescript로 변환

멘토에게

  • 리뷰 부탁드립니다 :)

@maclovedany maclovedany requested a review from dongqui May 23, 2025 01:47
@maclovedany maclovedany added the 순한맛🐑 마음이 많이 여립니다.. label May 23, 2025
Copy link
Collaborator

@dongqui dongqui left a comment

Choose a reason for hiding this comment

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

경훈님 요즘 정말 열심히 달리시는군요!! 👍 👍

타입스크립트로 잘 넘어가고 계신 거 같습니다 :)
제네릭, 유틸 타입 같은 것들도 적극 사용해 보시면 더욱 좋을 거 같습니다~!

type: "email" | "text" | "password";
placeholder: string;
value: string;
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
Copy link
Collaborator

Choose a reason for hiding this comment

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

 onChange: ChangeEventHandler<HTMLInputElement>;

이렇게 쓰실 수 있어요!

placeholder: string;
value: string;
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
onBlur?: (e: FocusEvent<HTMLInputElement>) => void; // onBlur는 선택적
Copy link
Collaborator

Choose a reason for hiding this comment

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

위와 마찬가지 입니다!

  onBlur?: FocusEventHandler<HTMLInputElement>;

onToggleShowPassword?: () => void; // 토글 함수
}

const AuthFormField: React.FC<AuthFormFieldProps> = ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

크게 상관은 없는데..
암시적인 children 포함, 제네릭 활용 어려움 등의 이유로 FC 타입은 지양되는 분위기가 있습니다. 실제로 CRA에서는 제거 되기도 했죠. 참고만 해주세요 :)

facebook/create-react-app#8177

@@ -0,0 +1,70 @@
import React, { ChangeEvent, FocusEvent } from "react";

interface AuthFormFieldProps {
Copy link
Collaborator

Choose a reason for hiding this comment

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

html 기본 속성의 경우 아래처럼 표현할 수 있습니다.

interface AuthFormFieldProps extends InputHTMLAttributes<HTMLInputElement> {
  error?: string;
  //... html 속성 제외 커스텀 프랍들
}

import { Link as RouterLink } from "react-router-dom";

// HomePage.tsx, SigninPage.tsx, SignupPage.tsx 에서 사용된 Link 타입 문제 임시 해결
const Link: any = RouterLink;
Copy link
Collaborator

Choose a reason for hiding this comment

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

as RouterLink만 지워도 타입 문제는 딱히 없지 않나요!? 🤔

import { Link } from "react-router-dom";

import { useState, ChangeEvent, FormEvent, FocusEvent } from "react";
import { useNavigate } from "react-router-dom";

export const useSignupForm = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

상태 값이 상당히 늘어나는데, react-hook-form 그리고 타입스크립트도 시작하셨으니 zod를 함께 써보시면 좋습니다!!

import { formatTimeAgo } from "../utils/timeFormat"; // 경로가 정확한지 확인 필요

function useComments(productId) {
const [comments, setComments] = useState([]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

아직 타입 적용이 안 됐군요! 복잡한 객체의 상태를 정의할 때 제네릭을 쓰시면 좋습니다 :)

// 서버 응답에서 업데이트된 isFavorite와 favoriteCount를 받아 상태를 갱신합니다.
// API 응답이 전체 product 객체를 반환한다면 setProduct(data)를 사용할 수 있습니다.
// 그렇지 않다면, 부분적으로 상태를 업데이트해야 합니다.
setProduct((prevProduct) => ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

좋아요 버튼의 경우 낙관적 UI를 많이 씁니다 :)

https://jong6598.tistory.com/34

fetchComments();
}
}, [loading, product, fetchComments]);
const { product, loadingProduct, productError, handleFavoriteClick } =
Copy link
Collaborator

Choose a reason for hiding this comment

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

오.. 상당히 많은 정리가 있었군요..! 👍

@dongqui dongqui merged commit e638008 into codeit-bootcamp-frontend:React-차경훈 May 23, 2025
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