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

feat: http 요청 custom hooks 작성 #76

Merged
merged 3 commits into from
Nov 24, 2022
Merged

feat: http 요청 custom hooks 작성 #76

merged 3 commits into from
Nov 24, 2022

Conversation

gchoi96
Copy link
Member

@gchoi96 gchoi96 commented Nov 24, 2022

Feature

http 관련 custom hooks 작성

  • 배경
    • http 요청을 보낼 때마다 작성해야하는 코드가 많고, 가독성이 떨어짐
  • 목적
    • http 요청 관련 로직을 custom hooks로 분리

과정

  • useHttpGet, useHttpPost, useHttpPatch 훅 작성
  • 기존 http 요청 부분 변경

결과 (스크린샷 등)

AS-IS

   const onSubmitSignUp = async () => {
        if (!checkFormValidation()) return;
        axios
            .post("http://localhost:4000/user", {
                userId,
                password,
                pace: pace.minute * 60 + pace.second,
                hCode,
            })
            .then((res) => res.status === 201 && navigate("/", { replace: true }))
            .catch(console.log);
    };

TO-BE

   const { post } = usePost();
   const onSubmitSignUp = async () => {
        if (!checkFormValidation()) return;
        try {
            await post("/user", { userId, password, hCode, pace: pace.minute * 60 + pace.second });
            navigate("/", { replace: true });
        } catch (error: any) {
            alert(error.message);
        }
    };

관련 issue 번호 (링크)

테스트 방법

Commit

@gchoi96 gchoi96 self-assigned this Nov 24, 2022
Copy link
Member

@June1010 June1010 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@claycat claycat left a comment

Choose a reason for hiding this comment

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

LGTM

@pushedrumex pushedrumex merged commit c81e622 into develop Nov 24, 2022
@gchoi96 gchoi96 deleted the feat/axios branch December 1, 2022 11:43
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.

4 participants