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: 설문이 있을 때 핸들링 #491

Merged
Changes from 1 commit
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
21 changes: 19 additions & 2 deletions src/pages/survey/base.page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import { useEffect } from 'react';
import { type NextPage } from 'next';
import Image from 'next/image';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { css, type Theme } from '@emotion/react';

import BottomBar from '~/components/bottomBar/BottomBar';
import Button from '~/components/button/Button';
import FixedSpinner from '~/components/loading/FixedSpinner';
import LoadingHandler from '~/components/loading/LoadingHandler';
import useGetSurveyIdByUserStatus from '~/hooks/api/surveys/useGetSurveyIdByUserStatus';
import { HEAD_1 } from '~/styles/typo';

const SurveyBasePage: NextPage = () => {
const router = useRouter();
const { data, isLoading } = useGetSurveyIdByUserStatus();
const hasSurvey = Boolean(data?.survey_id);

useEffect(
function replaceWhenHasSurvey() {
if (isLoading) return;
if (hasSurvey) router.replace('/result');
},
[hasSurvey, isLoading, router],
Comment on lines +21 to +25
Copy link
Member

Choose a reason for hiding this comment

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

�useEffect 안의 함수에 이름을 지정해둔 이유가 있을까요? 👀

Copy link
Member Author

Choose a reason for hiding this comment

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

오호호 이건 모던 리액트 딥다이브에 나온 내용이기도 한데요

제 생각과 함께 설명드리자면

이펙트에 기명함수를 쓰면 좋은 점은

  1. 이펙트의 역할 명시 (그냥 이펙트만 있으면 해당 이펙트의 역할을 코드를 읽어야 알 수 있음)
  2. 메모리 디버깅 시 이점 (익명 함수는 찾기가 어려워 어느 함수인지 알지못함)

요런 이유가 있습니다 ~

그래서 간단한 이펙트가 아니면 전 ㅁ쓰려고 하곤해용

);

return (
<>
<LoadingHandler isLoading={isLoading} fallback={<FixedSpinner />}>
<main css={mainCss}>
<h1 css={h1Css}>
질문 폼을 생성하고
Expand All @@ -27,7 +44,7 @@ const SurveyBasePage: NextPage = () => {
</main>

<BottomBar />
</>
</LoadingHandler>
);
};

Expand Down
Loading