์ปดํฌ๋„ŒํŠธ ๋‚ด๋ถ€์—์„œ router ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ํ•˜๋Š” ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ•

์ปดํฌ๋„ŒํŠธ ๋‚ด๋ถ€์—์„œ router ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ํ•˜๋Š” ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ•

Profile Picture
adultlee
2023-11-22

์›๋ณธ

์„œ๋ฌธ

ํ˜„์žฌ ๋ฉด์ ‘์—ฐ์Šต์„œ๋น„์Šค์ธ Gomterview Git๋ฅผ ๊ฐœ๋ฐœ ์ค‘์ž…๋‹ˆ๋‹ค. ์ด์ „์˜ ์ œ ํฌ์ŠคํŒ… ์ค‘ ํ•˜๋‚˜์ธ createBrowserRouter ๋ฅผ ํ†ตํ•œ ๋ผ์šฐํ„ฐ ์ฒ˜๋ฆฌ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋“ฏ, ์ €ํฌ ์„œ๋น„์Šค๋Š” createBrowserRouter๋ฅผ ํ†ตํ•ด์„œ router์ฒ˜๋ฆฌ๋ฅผ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋ฒˆ ๊ธ€์€ ํ•ด๋‹น createBrowserRouter๋ฅผ ํ†ตํ•œ ๋กœ์ง์—์„œ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ์™€ ์ด๋ฅผ ํ•ด๊ฒฐํ•œ ๋ฐฉ์‹์„ ๋‹ด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค!

CreateBrowserRouter ๊ธฐ๋ฐ˜์˜ loader๋Š” recoil ์œ„์—์„œ (์•ˆ์—์„œX) ๋™์ž‘ํ•œ๋‹ค

์ €ํฌ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด CreateBrowserRouter ๊ธฐ๋ฐ˜์˜ router๋ฅผ ์„ค์ •ํ•ด์ฃผ๊ธฐ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด ์ฃผ์—ˆ์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์ด path๋กœ ์ง„์ž…ํ•˜๋ คํ•˜๋Š” ๊ฒฝ์šฐ element์˜ <InterviewVideoPublicPage /> ๋กœ ์ด๋™์‹œํ‚ค๋ฉฐ, loader๋Š” ํŽ˜์ด์ง€์— ์ง„์ž…ํ•˜๊ธฐ ์ „ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ loadํ•˜๊ณ , ์‹คํŒจํ•œ๋‹ค๋ฉด redirect ์‹œ์ผœ์ฃผ๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ €๋Š” ์ง€๊ธˆ ์‚ฌ์ง„๊ณผ ๊ฐ™์ด InterviewViedoPublicLoader์—์„œ useIsAllSuccess๋ผ๋Š” hooks๋ฅผ ์‹คํ–‰์‹œ์ผœ์„œ ํ˜„์žฌ ์ „์—ญ์œผ๋กœ ์„ค์ •ํ•œ recoil ์ƒํƒœ๊ฐ’์„ ๋ฐ”ํƒ•์œผ๋กœ setting์ด ๋ชจ๋‘ ์ •ํ•ด์กŒ๋‹ค๋ฉด, ํ•ด๋‹น isAllSuccess์˜ ์œ ๋ฌด์— ๋”ฐ๋ผ์„œ ํŽ˜์ด์ง€์˜ routing์„ ์„ค์ •ํ•ด ์ฃผ๋ ค ํ–ˆ์Šต๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ useIsAllSuccess์—์„œ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.

React Hook "useIsAllSuccess" is called in function "interviewVideoPublicLoader" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use".eslintreact-hooks/rules-of-hooks

ํ•ด๋‹น ์—๋Ÿฌ๋Š” interviewVideoPublicLoader๋ผ๋Š” ํ•จ์ˆ˜๊ฐ€ React Router v6์˜ loader ํ•จ์ˆ˜ ๋‚ด์—์„œ useIsAllSuccess๋ผ๋Š” React ํ›…์„ ํ˜ธ์ถœํ•˜๊ณ  ์žˆ๋‹ค๋ฉด, ์ด๋Š” React์˜ ํ›… ์‚ฌ์šฉ ๊ทœ์น™์„ ์œ„๋ฐ˜ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•œ ๋ฌธ์ œ์˜€์Šต๋‹ˆ๋‹ค.

React Router์˜ loader ํ•จ์ˆ˜๋Š” React ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์•„๋‹ˆ๋ฏ€๋กœ, ์ด ์•ˆ์—์„œ React ํ›…์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์ด๋Š” React์˜ ๊ธฐ๋ณธ ๊ทœ์น™ ์ค‘ ํ•˜๋‚˜๋กœ, ํ›…์€ ์˜ค์ง React ํ•จ์ˆ˜ ์ปดํฌ๋„ŒํŠธ๋‚˜ ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž ์ •์˜ ํ›… ๋‚ด์—์„œ๋งŒ ํ˜ธ์ถœ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

React ํ›… ์‚ฌ์šฉ ๊ทœ์น™

ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ๋‚˜ user Custom Hooks ๋‚ด๋ถ€ ์—์„œ๋งŒ ํ˜ธ์ถœ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. React ํ›…์€ ๋ฐ˜๋“œ์‹œ ํ•จ์ˆ˜ ์ปดํฌ๋„ŒํŠธ๋‚˜ ์‚ฌ์šฉ์ž ์ •์˜ ํ›… ๋‚ด์—์„œ๋งŒ ํ˜ธ์ถœ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ผ๋ฐ˜ ํ•จ์ˆ˜, ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ์˜ ๋ฉ”์„œ๋“œ, ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ, ํƒ€์ด๋จธ ์ฝœ๋ฐฑ ๋“ฑ์—์„œ๋Š” ํ›…์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„  ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค.

1. ํ›… ํ˜ธ์ถœ ์œ„์น˜ ๋ณ€๊ฒฝ์„ ํ†ตํ•œ ํ•ด๊ฒฐ, useIsAllSuccess ํ›…์„ interviewVideoPublicLoader ํ•จ์ˆ˜๊ฐ€ ์•„๋‹Œ, ์ ์ ˆํ•œ ํ•จ์ˆ˜ ์ปดํฌ๋„ŒํŠธ ๋˜๋Š” ์‚ฌ์šฉ์ž ์ •์˜ ํ›… ๋‚ด๋ถ€๋กœ ์ด๋™

2. ์ƒํƒœ ๋˜๋Š” ๋ฐ์ดํ„ฐ ์ „๋‹ฌํ•˜์—ฌ ๋งŒ์•ฝ interviewVideoPublicLoader ํ•จ์ˆ˜๊ฐ€ ํŠน์ • ์ƒํƒœ์— ์˜์กดํ•˜๊ณ  ์žˆ๊ณ  ์ด ์ƒํƒœ๊ฐ€ useIsAllSuccess ํ›…์œผ๋กœ๋ถ€ํ„ฐ ์˜ค๋Š” ๊ฒƒ์ด๋ผ๋ฉด, ์ด ์ƒํƒœ๋ฅผ ๋ผ์šฐํ„ฐ์˜ loader ํ•จ์ˆ˜๋กœ ์ „๋‹ฌํ•˜๋Š” ๋Œ€์‹ , ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ๋‚˜ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ํ†ตํ•ด ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›๊ธฐ,

3. ๋กœ๋” ํ•จ์ˆ˜์™€ ์ปดํฌ๋„ŒํŠธ ๋ถ„๋ฆฌ๋ฅผ ๋ถ„๋ฆฌํ•˜์—ฌ loader ํ•จ์ˆ˜์—์„œ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋กœ๋“œํ•˜๊ณ , ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ ๋‚ด์—์„œ useIsAllSuccess์™€ ๊ฐ™์€ ํ›…์„ ์‚ฌ์šฉํ•˜์—ฌ ์ถ”๊ฐ€์ ์ธ ์ƒํƒœ ๊ด€๋ฆฌ ์ฒ˜๋ฆฌ

์ฆ‰ recoil ๊ธฐ๋ฐ˜์˜ hooks๋ฅผ ํ†ตํ•ด์„œ routing์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด์„  ํŽ˜์ด์ง€ ๋‚ด๋ถ€๋กœ ์ด๋™ํ•ด์„œ ํ•ด๊ฒฐํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

ํŽ˜์ด์ง€ ์ปดํฌ๋„ŒํŠธ ๋‚ด๋ถ€์—์„œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ

์šฐ๋ฆฌ๋Š” ์œ„์—์„œ ์ด๋Ÿฐ ๊ฒฐ๋ก ์„ ๋‚ด๋ฆด์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. "recoil ๊ธฐ๋ฐ˜์˜ hooks๋ฅผ ํ†ตํ•œ ํŽ˜์ด์ง€ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋Š” createBrowserRouter์™€ ๊ฐ™์€ ์™ธ๋ถ€์—์„œ๋Š” ๋™์ž‘์ด ๋ถˆ๊ฐ€ํ•˜๋‹ค. ์ฆ‰ ํŽ˜์ด์ง€ ๋‚ด๋ถ€์—์„œ ํ•ด๊ฒฐํ•ด์•ผํ•œ๋‹ค." ๋ผ๋Š” ๊ฒฐ๋ก ์„ ๋‚ด๋ ธ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜๋Š” ์ œ๊ฐ€ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ์ง„ํ–‰ํ•˜๊ณ  ์‹ถ์€ Interview ๋ฅผ ์ง„ํ–‰ํ•˜๋Š” InterviewPage ์ปดํฌ๋„ŒํŠธ ์ž…๋‹ˆ๋‹ค.

ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด router ์ฒ˜๋ฆฌ๋ฅผ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.

InterviewPage ์ปดํฌ๋„ŒํŠธ

const InterviewPage: React.FC = () => {
  const { method } = useRecoilValue(recordSetting);
  const { currentQuestion, getNextQuestion, isLastQuestion } =
    useInterviewFlow();

  const [stream, setStream] = useState<MediaStream | null>(null);
  const [isRecording, setIsRecording] = useState(false);
  const [isScriptInView, setIsScriptInView] = useState(true);
  const [recordedBlobs, setRecordedBlobs] = useState<Blob[]>([]);
  const [selectedMimeType, setSelectedMimeType] = useState('');
  const [interviewIntroModalIsOpen, setInterviewIntroModalIsOpen] =
    useState<boolean>(true);

  // .... ๊ต‰์žฅํžˆ ๋งŽ์€ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง...

return (
    <InterviewPageLayout>
      <InterviewHeader
        isRecording={isRecording}
        intervieweeName={intervieweeName}
      />
      <InterviewMain
        mirrorVideoRef={mirrorVideoRef}
        isScriptInView={isScriptInView}
        question={currentQuestion.questionContent}
        answer={currentQuestion.answerContent}
      />
   // .... ๊ต‰์žฅํžˆ ๋งŽ์€ ์ปดํฌ๋„ŒํŠธ ๋“ค...

๋‹ค์Œ๊ณผ ๊ฐ™์ด ํŽ˜์ด์ง€ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ณด๋ฉด ์ˆ˜๋งŽ์€ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง์„ ๋‹ด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด ํŽ˜์ด์ง€์—๋Š” ์ ์ ˆํ•œ ๊ถŒํ•œ์„ ๊ฐ–์ถ˜ ์œ ์ €๋งŒ์ด ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ ๊ตฌํ˜„ํ•œ ๋ฐฉ์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค! ์ œ๊ฐ€ ์ƒ๊ฐํ•œ ๋กœ์ง์€ ํŽ˜์ด์ง€ ์ƒ๋‹จ์—์„œ isAllSuccess๋ผ๋Š” boolean ์š”์†Œ๋กœ ์ธํ•ด์„œ ํŽ˜์ด์ง€์˜ ๋ผ์šฐํŒ…์„ ๊ฒฐ์ •ํ•˜๋Š” ๊ฒƒ์ด์—ˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด๋•Œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ๋ฉ๋‹ˆ๋‹ค. ์ด ๊ฒฝ๊ณ  ๋ฉ”์„ธ์ง€๋Š” navigate ํ•จ์ˆ˜๋ฅผ useEffect์™ธ๋ถ€์—์„œ ์‚ฌ์šฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•œ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.

React์˜ ๋ Œ๋”๋ง ์‚ฌ์ดํด๊ณผ ์‚ฌ์ด๋“œ ์ดํŽ™ํŠธ

React ์ปดํฌ๋„ŒํŠธ๋Š” ์—ฌ๋Ÿฌ ๋ผ์ดํ”„์‚ฌ์ดํด ๋‹จ๊ณ„๋ฅผ ๊ฑฐ์น˜๋ฉฐ ๋ Œ๋”๋ง๋ฉ๋‹ˆ๋‹ค. ์ดˆ๊ธฐ ๋ Œ๋”๋ง ์‹œ์—๋Š” ์ปดํฌ๋„ŒํŠธ๊ฐ€ DOM์— ์ฒ˜์Œ์œผ๋กœ ๋งˆ์šดํŠธ๋˜๋Š” ๋‹จ๊ณ„์ž…๋‹ˆ๋‹ค. ์ด ๋‹จ๊ณ„์—์„œ ์‚ฌ์ด๋“œ ์ดํŽ™ํŠธ(์˜ˆ: ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ, ํƒ€์ด๋จธ ์„ค์ •, ๋„ค๋น„๊ฒŒ์ด์…˜ ๋“ฑ)๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. useEffect ํ›…์€ ์ปดํฌ๋„ŒํŠธ ๋ Œ๋”๋ง ์ดํ›„์— ์‚ฌ์ด๋“œ ์ดํŽ™ํŠธ๋ฅผ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์œ„ํ•œ React์˜ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. useEffect ์‚ฌ์šฉํ•˜๋ฉด React๊ฐ€ DOM ์—…๋ฐ์ดํŠธ๋ฅผ ์™„๋ฃŒํ•œ ํ›„์— ์‚ฌ์ด๋“œ ์ดํŽ™ํŠธ๋ฅผ ์•ˆ์ „ํ•˜๊ฒŒ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

navigate() & useEffect

์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ฒ˜์Œ ๋ Œ๋”๋ง๋  ๋•Œ navigate()๋ฅผ ์ง์ ‘ ํ˜ธ์ถœํ•˜๋ฉด, ๋ Œ๋”๋ง ๊ณผ์ •์ด ์™„์ „ํžˆ ๋๋‚˜๊ธฐ ์ „์— ํŽ˜์ด์ง€ ๋„ค๋น„๊ฒŒ์ด์…˜์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ๋ Œ๋”๋ง ์‚ฌ์ดํด์„ ๋ฐฉํ•ดํ•˜๊ณ , ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ๋ Œ๋”๋ง ์ด์Šˆ๋‚˜ ๋ฒ„๊ทธ๋ฅผ ์ดˆ๋ž˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. useEffect ๋‚ด์—์„œ navigate()๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด, ์ปดํฌ๋„ŒํŠธ๊ฐ€ ํ™”๋ฉด์— ์™„์ „ํžˆ ๋งˆ์šดํŠธ๋œ ํ›„์— ๋„ค๋น„๊ฒŒ์ด์…˜์ด ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค. ์ด๋Š” ๋” ์•ˆ์ •์ผ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋ Œ๋”๋ง React์˜ ๋ Œ๋”๋ง ์‚ฌ์ดํด์— side effect๋ฅผ ๋ถ€๊ณผํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•˜๋ฉด, ์œ„์™€ ๊ฐ™์€ ๊ฒฝ๊ณ ๊ฐ€ ์‚ฌ๋ผ์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ์—ฌ๊ธฐ๊นŒ์ง€ ์ง„ํ–‰ํ•ด๋ณด๋ฉด ์‚ด์ง ์‹ ๊ฒฝ ์“ฐ์ด๋Š” ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

์ปดํฌ๋„ŒํŠธ๊ฐ€ ํ™”๋ฉด์— ์™„์ „ํžˆ ๋งˆ์šดํŠธ๋œ ํ›„์— ๋„ค๋น„๊ฒŒ์ด์…˜์ด ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๋ฉด ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ฌด์ˆ˜ํžˆ ๋งŽ๋‹ค๋ฉด...?

**๊ทธ ๋ฌด์ˆ˜ํžˆ ๋งŽ์€ ์ปดํฌ๋„ŒํŠธ์˜ ๋ Œ๋”๋ง์ด ๋ชจ๋‘ ๋งˆ์นœ ํ›„์—์•ผ navigate๊ฐ€ ๋™์ž‘ํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด, ์ด๋Š” ํฌ๋‚˜ํฐ ๋ฌธ์ œ๋ฅผ ์ผ์œผํ‚ฌ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. **

๋ฌผ๋ก  UI ์ƒ์—์„œ ๋ง‰๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์œผ๋‚˜ User๊ฐ€ ์ง์ ‘ url์„ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ์—๋Š” ๋Œ€์ฒ˜ํ•˜์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค. (์‚ฌ์‹ค ์ด๋ฅผ ๊ทน๋ณตํ•˜๊ธฐ ์œ„ํ•ด createBrowserRouter์˜ loader ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค ํ–ˆ์Šต๋‹ˆ๋‹ค.)

๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ€์žฅ ์ ์€ ๋น„์šฉ์œผ๋กœ ์ตœ์ ํ™”๊ฐ€ ํ•„์š”ํ–ˆ์Šต๋‹ˆ๋‹ค.

Navigate ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ™œ์šฉํ•ด์„œ ํ•ด๊ฒฐํ•ด๋ณด์ž

์‚ฌ์‹ค ์•„์ฃผ ๊ฐ„๋‹จํ•œ ํ•ด๊ฒฐ์ฑ…์ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. React Router์—์„œ ์ œ๊ณตํ•˜๋Š” Navigate ์ปดํฌ๋„ŒํŠธ๋Š” ์ด๋Ÿฌํ•œ ์ƒํ™ฉ์— ์ ํ•ฉํ•œ ํ•ด๊ฒฐ์ฑ…์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. Navigate ์ปดํฌ๋„ŒํŠธ๋Š” JSX ๋‚ด์—์„œ ์กฐ๊ฑด๋ถ€ ๋ Œ๋”๋ง์„ ํ†ตํ•ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์ด๋Š” useEffect์™€ navigate ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์„ ์–ธ์ ์ด๊ณ  ์ง๊ด€์ ์ธ ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค!

๋ฌด์—‡๋ณด๋‹ค InterviewPageLayout์— ํ•ด๋‹นํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ๋“ค์„ ๋ชจ๋‘ ๋ Œ๋”๋ง ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์ ์€ ๊ฝค๋‚˜ ๋งค๋ ฅ์ ์ž…๋‹ˆ๋‹ค.

๋งบ์Œ๋ง

์‚ฌ์‹ค ์—ฌ๊ธฐ๊นŒ์ง€ ์ž˜ ์ฝ์œผ์…จ๋‹ค๋ฉด, ์•„์ง ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค๋Š” ์ ์„ ์ •๋ง ์‰ฝ๊ฒŒ ๋ˆˆ์น˜ ์ฑ„์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์˜ ํ•˜๋‹จ์˜ return ๊ตฌ๋ฌธ์—์„œ Navigate๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด, ์•„๋ž˜์˜ ์ปดํฌ๋„ŒํŠธ๋“ค์„ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ์ „์— Navigate ๊ฐ€ ๋™์ž‘ํ•˜๊ฒŒ ๋˜์ง€๋งŒ, ํ•ด๋‹น ์ปดํฌ๋„ŒํŠธ์˜ ๋ชจ๋“  ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง์ด ๋™์ž‘ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๊ณ  ์ด๋ฅผ ๋ง‰๊ธฐ ์œ„ํ•ด์„œ ์ตœ์ƒ๋‹จ์—์„œ Navigate๋ฅผ ๋ฐ˜ํ™˜ํ•ด ๋ฒ„๋ฆฐ๋‹ค๋ฉด, rule of hooks ๋ผ๋Š” ๊ฒฝ๊ณ  ๊ฑธ๋ฆฌ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น ๊ฒฝ๊ณ ๋Š” hooks๊ฐ€ ํ˜ธ์ถœ๋˜๋Š” ์‹œ์ ์— ๋Œ€ํ•œ ๊ทœ์น™์„ ์˜๋ฏธํ•˜๋Š”๋ฐ, ์—ฌ๊ธฐ์„œ๋Š” ์ƒ๋‹จ์— Navigate๋ฅผ ๋ฐ˜ํ™˜ํ•ด ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง ๋ถ€๋ถ„์˜ hooks๊ฐ€ ํ˜ธ์ถœ์ด ๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์–ด ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ๊ณ  ์ž…๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ์™„๋ฒฝํ•˜์ง„ ์•Š์ง€๋งŒ ์ ์€ ๋น„์šฉ์œผ๋กœ ์ž‘์ง€ ์•Š์€ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐ ๊ทผ์ฒ˜๊นŒ์ง€ ๋„๋‹ฌํ•œ๋“ฏํ•ฉ๋‹ˆ๋‹ค.

ยฉ 2024 Adultlee. All rights reserved.Made with โค by ์ด์„ฑ์ธ