Skip to content

Commit

Permalink
Refactor: 로그인/회원가입 요청 react query 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
김보민 authored and 김보민 committed Jul 1, 2024
1 parent fcecbef commit 7a8bdff
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@hookform/error-message": "^2.0.1",
"@tanstack/react-query": "^5.49.0",
"@tanstack/react-query-devtools": "^5.49.0",
"axios": "^1.7.2",
"classnames": "^2.5.1",
"next": "^13.5.6",
Expand Down
9 changes: 8 additions & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import type { AppProps } from "next/app";
import "src/styles/global.css";

export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />;
const queryClient = new QueryClient();

return (
<QueryClientProvider client={queryClient}>
<Component {...pageProps} />
</QueryClientProvider>
);
}
16 changes: 7 additions & 9 deletions src/components/SignInForm/SignInForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ import styles from "./SingInForm.module.scss";
import classNames from "classnames/bind";
import { useForm } from "react-hook-form";
import { InputBox } from "../InputBox";
import {
postIdPwd,
regexData,
ApiUrl,
checkAccessToken,
postSignin,
} from "../../utils";
import { regexData, postSignin } from "../../utils";
import { useMutation } from "@tanstack/react-query";

const cx = classNames.bind(styles);

Expand Down Expand Up @@ -36,10 +31,13 @@ export function SignInForm() {
});

const onSubmit = (data) => {
console.log(data);
postSignin(data, setError);
postSigninMutaion.mutate(data, setError);
};

const postSigninMutaion = useMutation({
mutationFn: (data) => postSignin(data, setError),
});

return (
<form className={cx("form-wrapper")} onSubmit={handleSubmit(onSubmit)}>
<InputBox
Expand Down
8 changes: 6 additions & 2 deletions src/components/SignUpForm/SignUpForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import classNames from "classnames/bind";
import { useForm } from "react-hook-form";
import { InputBox } from "../InputBox";
import { checkDuplicateEmail, postSignUp, regexData } from "../../utils";
import { useMutation } from "@tanstack/react-query";

const cx = classNames.bind(styles);

Expand Down Expand Up @@ -41,10 +42,13 @@ export function SignUpForm() {
const onSubmit = (data) => {
const { email, password } = data;
const selectedData = { email, password };
console.log(selectedData);
postSignUp(selectedData);
postSignUpMutaion.mutate(selectedData);
};

const postSignUpMutaion = useMutation({
mutationFn: (data) => postSignUp(data),
});

return (
<form className={cx("form-wrapper")} onSubmit={handleSubmit(onSubmit)}>
<InputBox
Expand Down

0 comments on commit 7a8bdff

Please sign in to comment.