-
Notifications
You must be signed in to change notification settings - Fork 0
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
Featuring : 로그인 API 구현 #141
Conversation
Labeler가 제목과 설명에 있는 특별한 텍스트와 일치하는 레이블을 적용했습니다. |
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.
LGTM👍
mutateLogin( | ||
{ phoneNumber: data.phoneNumber }, | ||
{ | ||
onSuccess: (response: LoginResponse) => { | ||
if (response.existUser) { | ||
// TODO : 토큰 설정 & home으로 이동 | ||
} else { | ||
nextStep(); | ||
} | ||
}, | ||
} | ||
); |
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.
p2)useMutation의 option 값을 props로 받아서 처리하면 어떨까요?
지금은 mutate를 호출할 때 성공 로직을 적고 있는데 이렇게 되면 여러곳에서 mutate를 호출할 때마다 각각 로직을 작성해야 하는 번거로움이 있을 것 같아요.
커스텀 mutation 훅을 호출할 때 onSuccess 같은 핸들러 로직을 작성하게 하는건 어떨까요?
const { mutate: mutateLogin } = useLoginMutation({
onSuccess: handleSuccess
});
다른 프로젝트 예 : 커스텀 mutation, 사용
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.
이런 식으로도 로직 분리가 가능하군요. 위 링크에서는 공통적인 처리 로직이 있는 것으로 보입니다.
위 로그인의 경우 아래와 같이 로직을 분리해보았습니다.
const handleVerifySuccess = () => {
mutateLogin(
{ phoneNumber: getValues().phoneNumber },
{
onSuccess: (response: LoginResponse) => {
if (response.existUser) {
// TODO : 토큰 설정 & home으로 이동
} else {
nextStep();
}
},
}
);
};
const { mutate: mutateSMSVerify } = useSMSVerifyMutation({
onSuccess: handleVerifySuccess,
});
const { mutate: mutateLogin } = useLoginMutation();
공통적으로 적용되는 로직이 아닌지라 다소 복잡해보이는데 어떠신가요 ??
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.
mutateLogin도 똑같이 훅의 인자로 onSuccess 처리해야하지 않을까요?
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.
SMSVerify 성공 -> Login 요청이 항상 동일하게 적용된다면 커스텀 훅 만든 곳에서 onSuccess 처리해도 될 것 같은데 어떻게 생각하시나요?
사용하는 쪽의 내부 상태를 바꿔야하는 경우가 아닐 때는 커스텀 훅 쪽에서 처리해도 좋을것 같아요! invalidQueries
같은 것들도 훅 쪽에서 처리하도록하면 사용할 때는 캐시 무효화 세팅 안해도 되는 장점도 있겠네용
💡 왜 PR을 올렸나요?
💁 무엇이 어떻게 바뀌나요?
💬 리뷰어분들께