์ฝ˜ํ…์ธ  ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ - ๐Ÿš€ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋กœ ์™„์„ฑํ•˜๋Š” ์„œ๋ฒ„์‚ฌ์ด๋“œ ๋ Œ๋”๋ง: Next.js ํƒ€์ž… ์‹œ์Šคํ…œ ์ตœ์ ํ™” ์™„๋ฒฝ ๊ฐ€์ด๋“œ

๐Ÿš€ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋กœ ์™„์„ฑํ•˜๋Š” ์„œ๋ฒ„์‚ฌ์ด๋“œ ๋ Œ๋”๋ง: Next.js ํƒ€์ž… ์‹œ์Šคํ…œ ์ตœ์ ํ™” ์™„๋ฒฝ ๊ฐ€์ด๋“œ

SSR๊ณผ ํƒ€์ž… ์•ˆ์ •์„ฑ, ๋‘ ๋งˆ๋ฆฌ ํ† ๋ผ๋ฅผ ํ•œ ๋ฒˆ์— ์žก๋Š” ์‹ค์ „ ๋…ธํ•˜์šฐ

๐Ÿ’ก ์ด ๊ธ€์„ ์ฝ์œผ๋ฉด ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์™€ Next.js๋ฅผ ํ™œ์šฉํ•œ ์„œ๋ฒ„์‚ฌ์ด๋“œ ๋ Œ๋”๋ง์˜ ํ•ต์‹ฌ ๊ฐœ๋…๋ถ€ํ„ฐ ์‹ค์ „ ์ตœ์ ํ™” ๊ธฐ๋ฒ•๊นŒ์ง€, ํ˜„์—…์—์„œ ๋ฐ”๋กœ ์ ์šฉ ๊ฐ€๋Šฅํ•œ ๊ตฌ์ฒด์ ์ธ ๋ฐฉ๋ฒ•๋“ค์„ ๋ฐฐ์šธ ์ˆ˜ ์žˆ์–ด. ํƒ€์ž… ์•ˆ์ •์„ฑ์„ ์œ ์ง€ํ•˜๋ฉด์„œ๋„ ์„ฑ๋Šฅ์„ ๊ทน๋Œ€ํ™”ํ•˜๋Š” ๋น„๋ฒ•์„ ์นœ๊ตฌ์ฒ˜๋Ÿผ ํŽธํ•˜๊ฒŒ ์•Œ๋ ค์ค„๊ฒŒ! ๐ŸŽฏ

๐ŸŽฌ ์™œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์™€ SSR์„ ํ•จ๊ป˜ ์จ์•ผ ํ• ๊นŒ?

์ž, ๋จผ์ € ์†”์งํ•˜๊ฒŒ ์–˜๊ธฐํ•ด๋ณด์ž. ๋„ˆ๋„ ์•Œ๋‹ค์‹œํ”ผ ์š”์ฆ˜ ์›น ๊ฐœ๋ฐœ ํŠธ๋ Œ๋“œ๋Š” ์™„์ „ํžˆ ๋ฐ”๋€Œ์—ˆ์–ด. ์˜ˆ์ „์ฒ˜๋Ÿผ ๋‹จ์ˆœํžˆ "์ž‘๋™๋งŒ ํ•˜๋ฉด ๋ผ!"๋ผ๋Š” ์‹œ๋Œ€๋Š” ์ง€๋‚ฌ์ง€. ์‚ฌ์šฉ์ž๋“ค์€ ๋น ๋ฅธ ์ดˆ๊ธฐ ๋กœ๋”ฉ์„ ์›ํ•˜๊ณ , ๊ฒ€์ƒ‰ ์—”์ง„์€ ์ œ๋Œ€๋กœ ๋œ SEO๋ฅผ ์š”๊ตฌํ•˜๊ณ , ๊ฐœ๋ฐœํŒ€์€ ์œ ์ง€๋ณด์ˆ˜ ๊ฐ€๋Šฅํ•œ ์ฝ”๋“œ๋ฅผ ์›ํ•ด. ์ด ๋ชจ๋“  ๊ฑธ ํ•œ ๋ฒˆ์— ํ•ด๊ฒฐํ•˜๋Š” ๊ฒŒ ๋ฐ”๋กœ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ + Next.js SSR ์กฐํ•ฉ์ด์•ผ! ๐Ÿ˜Ž

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์— ํƒ€์ž… ์‹œ์Šคํ…œ์„ ๋”ํ•œ ๊ฑฐ์ž–์•„? ์ด๊ฒŒ ์™œ ์ค‘์š”ํ•˜๋ƒ๋ฉด, ์„œ๋ฒ„์‚ฌ์ด๋“œ ๋ Œ๋”๋ง ํ™˜๊ฒฝ์—์„œ๋Š” ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„ ์–‘์ชฝ์—์„œ ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋˜๊ธฐ ๋•Œ๋ฌธ์— ํƒ€์ž… ์•ˆ์ •์„ฑ์ด ๋”์šฑ ์ค‘์š”ํ•ด์ ธ. ์„œ๋ฒ„์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์™€์„œ ํด๋ผ์ด์–ธํŠธ๋กœ ์ „๋‹ฌํ•˜๋Š” ๊ณผ์ •์—์„œ ํƒ€์ž…์ด ๋งž์ง€ ์•Š์œผ๋ฉด? ๋Ÿฐํƒ€์ž„ ์—๋Ÿฌ๊ฐ€ ํ„ฐ์ง€๋Š” ๊ฑด ์‹œ๊ฐ„๋ฌธ์ œ์•ผ. ๐Ÿ”ฅ

Next.js๋Š” ๋ฆฌ์•กํŠธ ๊ธฐ๋ฐ˜์˜ ํ”„๋ ˆ์ž„์›Œํฌ์ธ๋ฐ, SSR์„ ์ •๋ง ์‰ฝ๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค˜. ๊ทธ๋ƒฅ ํŒŒ์ผ ํ•˜๋‚˜ ๋งŒ๋“ค๋ฉด ์ž๋™์œผ๋กœ ๋ผ์šฐํŒ…๋„ ๋˜๊ณ , `getServerSideProps`๋‚˜ `getStaticProps` ๊ฐ™์€ ํ•จ์ˆ˜๋งŒ exportํ•˜๋ฉด ์„œ๋ฒ„์‚ฌ์ด๋“œ ๋ Œ๋”๋ง์ด ๋š๋”ฑ ์™„์„ฑ๋ผ. ์—ฌ๊ธฐ์— ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋ฅผ ์–น์œผ๋ฉด? ์™„๋ฒฝํ•œ ํƒ€์ž… ์ถ”๋ก ๊ณผ ์ž๋™์™„์„ฑ๊นŒ์ง€ ๋ค์œผ๋กœ ์–ป๋Š” ๊ฑฐ์ง€! ๐ŸŽ
๐Ÿ” ์‹ค์ œ ์‚ฌ๋ก€๋กœ ๋ณด๋Š” ํšจ๊ณผ ํ•œ ์ด์ปค๋จธ์Šค ํšŒ์‚ฌ์—์„œ CSR(ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง)์—์„œ SSR๋กœ ์ „ํ™˜ํ–ˆ๋”๋‹ˆ ์ดˆ๊ธฐ ๋กœ๋”ฉ ์†๋„๊ฐ€ 40% ๊ฐœ์„ ๋๊ณ , ๊ตฌ๊ธ€ ๊ฒ€์ƒ‰ ๋…ธ์ถœ์ด 3๋ฐฐ ์ฆ๊ฐ€ํ–ˆ๋Œ€. ์—ฌ๊ธฐ์— ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋„์ž…ํ•˜๋‹ˆ๊นŒ ๋Ÿฐํƒ€์ž„ ์—๋Ÿฌ๊ฐ€ 70% ๊ฐ์†Œํ–ˆ๋‹ค๋Š” ํ†ต๊ณ„๋„ ์žˆ์–ด. ์ˆซ์ž๊ฐ€ ๋งํ•ด์ฃผ๋Š” ๊ฑฐ์ง€! ๐Ÿ“Š
ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ + Next.js SSR ์•„ํ‚คํ…์ฒ˜ ๋ธŒ๋ผ์šฐ์ € ํด๋ผ์ด์–ธํŠธ ํƒ€์ž… ์ฒดํฌ ์™„๋ฃŒ๋œ ์•ˆ์ „ํ•œ ์ฝ”๋“œ ์‹คํ–‰ Next.js ์„œ๋ฒ„ ์„œ๋ฒ„์‚ฌ์ด๋“œ ํƒ€์ž… ์•ˆ์ •์„ฑ ๋ณด์žฅ ๋ฐ์ดํ„ฐ ํ”„๋ฆฌ๋ Œ๋”๋ง ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํƒ€์ž… ์‹œ์Šคํ…œ ์–‘๋ฐฉํ–ฅ ํƒ€์ž… ์ฒดํฌ ์ปดํŒŒ์ผ ํƒ€์ž„ ์—๋Ÿฌ ๊ฒ€์ถœ

โš™๏ธ Next.js์—์„œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ์„ธํŒ…ํ•˜๊ธฐ

์ข‹์•„, ์ด์ œ ๋ณธ๊ฒฉ์ ์œผ๋กœ ์‹œ์ž‘ํ•ด๋ณด์ž! Next.js ํ”„๋กœ์ ํŠธ์— ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋ฅผ ์„ธํŒ…ํ•˜๋Š” ๊ฑด ์ƒ๊ฐ๋ณด๋‹ค ํ›จ์”ฌ ๊ฐ„๋‹จํ•ด. Next.js ํŒ€์ด ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋ฅผ 1๊ธ‰ ์‹œ๋ฏผ(first-class citizen)์œผ๋กœ ๋Œ€์šฐํ•˜๊ฑฐ๋“ . ๐Ÿ˜Š

๐Ÿ’š ์ดˆ๋ณด์ž ํŒ ์ด๋ฏธ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ๋œ Next.js ํ”„๋กœ์ ํŠธ๊ฐ€ ์žˆ๋‹ค๋ฉด? ๊ฑฑ์ • ๋งˆ! ์ ์ง„์ ์œผ๋กœ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ํ•  ์ˆ˜ ์žˆ์–ด. ํŒŒ์ผ ํ™•์žฅ์ž๋ฅผ `.js`์—์„œ `.tsx`๋กœ ํ•˜๋‚˜์”ฉ ๋ฐ”๊ฟ”๊ฐ€๋ฉด์„œ ํƒ€์ž…์„ ์ถ”๊ฐ€ํ•˜๋ฉด ๋ผ. ํ•œ ๋ฒˆ์— ๋‹ค ๋ฐ”๊ฟ€ ํ•„์š” ์—†์–ด! ๐ŸŽฏ
์ƒˆ ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•œ๋‹ค๋ฉด ์ด๋ ‡๊ฒŒ ํ•ด๋ด:
npx create-next-app@latest my-app --typescript
cd my-app
npm run dev
๋! ์ด๊ฒŒ ๋‹ค์•ผ. Next.js๊ฐ€ ์•Œ์•„์„œ `tsconfig.json` ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๊ณ , ํ•„์š”ํ•œ ํƒ€์ž… ์ •์˜ ํŒŒ์ผ๋“ค๋„ ์„ค์น˜ํ•ด์ค˜. ์ •๋ง ์นœ์ ˆํ•˜์ง€? ๐Ÿ˜„

๋งŒ์•ฝ ๊ธฐ์กด ํ”„๋กœ์ ํŠธ์— ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด:
npm install --save-dev typescript @types/react @types/node
touch tsconfig.json
npm run dev
๊ฐœ๋ฐœ ์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•˜๋ฉด Next.js๊ฐ€ ์ž๋™์œผ๋กœ `tsconfig.json`์„ ์ฑ„์›Œ์ค˜. ์ด๊ฒŒ Next.js์˜ ๋งˆ๋ฒ•์ด์•ผ! โœจ

๐Ÿ“ tsconfig.json ํ•ต์‹ฌ ์„ค์ • Next.js๊ฐ€ ์ž๋™์œผ๋กœ ์ƒ์„ฑํ•ด์ฃผ๋Š” ์„ค์ •์ด ๋Œ€๋ถ€๋ถ„ ์™„๋ฒฝํ•˜์ง€๋งŒ, ๋ช‡ ๊ฐ€์ง€๋Š” ์•Œ์•„๋‘๋ฉด ์ข‹์•„:

โ€ข strict: true - ์—„๊ฒฉํ•œ ํƒ€์ž… ์ฒดํฌ ํ™œ์„ฑํ™” (๊ฐ•๋ ฅ ์ถ”์ฒœ!)
โ€ข noImplicitAny: true - any ํƒ€์ž… ์•”๋ฌต์  ์‚ฌ์šฉ ๊ธˆ์ง€
โ€ข strictNullChecks: true - null/undefined ์ฒดํฌ ๊ฐ•ํ™”
โ€ข esModuleInterop: true - CommonJS ๋ชจ๋“ˆ ํ˜ธํ™˜์„ฑ
โ€ข jsx: "preserve" - Next.js๊ฐ€ JSX ๋ณ€ํ™˜ ์ฒ˜๋ฆฌ

์ด ์„ค์ •๋“ค์ด ํƒ€์ž… ์•ˆ์ •์„ฑ์˜ ๊ธฐ์ดˆ๋ฅผ ๋งŒ๋“ค์–ด์ค˜! ๐Ÿ—๏ธ

๐ŸŽจ ํŽ˜์ด์ง€ ์ปดํฌ๋„ŒํŠธ ํƒ€์ž… ์ •์˜ํ•˜๊ธฐ

์ž, ์ด์ œ ์‹ค์ „์ด์•ผ! Next.js์—์„œ ํŽ˜์ด์ง€๋ฅผ ๋งŒ๋“ค ๋•Œ ํƒ€์ž…์„ ์–ด๋–ป๊ฒŒ ์ •์˜ํ•˜๋Š”์ง€ ์•Œ์•„๋ณด์ž. ํŽ˜์ด์ง€ ์ปดํฌ๋„ŒํŠธ๋Š” ํฌ๊ฒŒ ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์œผ๋กœ ํƒ€์ž…์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ์–ด.

1. ๊ธฐ๋ณธ ํŽ˜์ด์ง€ ์ปดํฌ๋„ŒํŠธ ํƒ€์ž…

๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ํŽ˜์ด์ง€๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด๋ณผ๊นŒ:
import type { NextPage } from 'next'

const Home: NextPage = () => {
  return (
    <div>
      <h1>์•ˆ๋…•ํ•˜์„ธ์š”! ํƒ€์ž… ์•ˆ์ „ํ•œ ํŽ˜์ด์ง€์ž…๋‹ˆ๋‹ค ๐ŸŽ‰</h1>
    </div>
  )
}

export default Home
`NextPage` ํƒ€์ž…์„ ์‚ฌ์šฉํ•˜๋ฉด Next.js ํŽ˜์ด์ง€ ์ปดํฌ๋„ŒํŠธ์˜ ๊ธฐ๋ณธ ํƒ€์ž…์ด ์ž๋™์œผ๋กœ ์ ์šฉ๋ผ. ๊ฐ„๋‹จํ•˜์ง€? ๐Ÿ˜Š

2. Props๋ฅผ ๋ฐ›๋Š” ํŽ˜์ด์ง€ ์ปดํฌ๋„ŒํŠธ

์‹ค์ œ๋กœ๋Š” ๋Œ€๋ถ€๋ถ„ ์„œ๋ฒ„์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์™€์„œ props๋กœ ์ „๋‹ฌํ•˜์ž–์•„? ์ด๋Ÿด ๋•Œ๋Š” ์ œ๋„ค๋ฆญ์„ ์‚ฌ์šฉํ•ด:
import type { NextPage } from 'next'

interface UserData {
  id: number
  name: string
  email: string
  createdAt: string
}

interface HomeProps {
  users: UserData[]
  totalCount: number
}

const Home: NextPage<HomeProps> = ({ users, totalCount }) => {
  return (
    <div>
      <h1>์ „์ฒด ์‚ฌ์šฉ์ž: {totalCount}๋ช…</h1>
      {users.map(user => (
        <div key={user.id}>
          <p>{user.name} ({user.email})</p>
        </div>
      ))}
    </div>
  )
}

export default Home
์ด๋ ‡๊ฒŒ ํ•˜๋ฉด `users`์™€ `totalCount`์˜ ํƒ€์ž…์ด ๋ช…ํ™•ํ•˜๊ฒŒ ์ •์˜๋ผ์„œ, ์ปดํฌ๋„ŒํŠธ ๋‚ด๋ถ€์—์„œ ์ž๋™์™„์„ฑ๋„ ๋˜๊ณ  ํƒ€์ž… ์ฒดํฌ๋„ ์™„๋ฒฝํ•˜๊ฒŒ ๋ผ! ๐ŸŽฏ

โš ๏ธ ์ฃผ์˜์‚ฌํ•ญ Next.js 13 ์ด์ƒ์—์„œ App Router๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด `NextPage` ํƒ€์ž… ๋Œ€์‹  ์ผ๋ฐ˜ React ์ปดํฌ๋„ŒํŠธ ํƒ€์ž…์„ ์‚ฌ์šฉํ•ด์•ผ ํ•ด. App Router๋Š” ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๊ธฐ๋ณธ์ด๋ผ์„œ ํƒ€์ž… ์ •์˜ ๋ฐฉ์‹์ด ์กฐ๊ธˆ ๋‹ฌ๋ผ. ๋ฒ„์ „ ํ™•์ธ์€ ํ•„์ˆ˜! ๐Ÿ“Œ

๐Ÿš€ getServerSideProps ํƒ€์ž… ์ตœ์ ํ™”

์ž, ์ด์ œ ์ง„์งœ ํ•ต์‹ฌ์œผ๋กœ ๋“ค์–ด๊ฐ€๋ณด์ž! SSR์˜ ๊ฝƒ์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋Š” `getServerSideProps`์˜ ํƒ€์ž… ์ •์˜์•ผ. ์ด๊ฒŒ ์ œ๋Œ€๋กœ ์•ˆ ๋˜๋ฉด ์„œ๋ฒ„์™€ ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด์—์„œ ํƒ€์ž… ๋ถˆ์ผ์น˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์–ด. ๐Ÿ˜ฑ

๊ธฐ๋ณธ ํƒ€์ž… ์ •์˜

Next.js๋Š” `GetServerSideProps` ํƒ€์ž…์„ ์ œ๊ณตํ•ด์ค˜:
import type { GetServerSideProps, NextPage } from 'next'

interface Product {
  id: string
  name: string
  price: number
  description: string
  inStock: boolean
}

interface ProductPageProps {
  product: Product
  relatedProducts: Product[]
}

export const getServerSideProps: GetServerSideProps<ProductPageProps> = async (context) => {
  const { id } = context.params as { id: string }
  
  // API ํ˜ธ์ถœ
  const productRes = await fetch(`https://api.example.com/products/${id}`)
  const product: Product = await productRes.json()
  
  const relatedRes = await fetch(`https://api.example.com/products/${id}/related`)
  const relatedProducts: Product[] = await relatedRes.json()
  
  return {
    props: {
      product,
      relatedProducts
    }
  }
}

const ProductPage: NextPage<ProductPageProps> = ({ product, relatedProducts }) => {
  return (
    <div>
      <h1>{product.name}</h1>
      <p>๊ฐ€๊ฒฉ: {product.price.toLocaleString()}์›</p>
      <p>{product.inStock ? '์žฌ๊ณ  ์žˆ์Œ โœ…' : 'ํ’ˆ์ ˆ โŒ'}</p>
    </div>
  )
}
์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ํฌ์ธํŠธ๋Š” `GetServerSideProps`์ฒ˜๋Ÿผ ์ œ๋„ค๋ฆญ์œผ๋กœ props ํƒ€์ž…์„ ๋ช…์‹œํ•˜๋Š” ๊ฑฐ์•ผ. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด `return { props: ... }` ๋ถ€๋ถ„์—์„œ ํƒ€์ž… ์ฒดํฌ๊ฐ€ ์ž๋™์œผ๋กœ ๋ผ! ๐ŸŽ‰

๐Ÿ”„ ํƒ€์ž… ์ •์˜ ์ „ vs ํ›„ ๋น„๊ต ํƒ€์ž… ์ •์˜ ์ „:
โ€ข props ์˜คํƒ€ ๋ฐœ์ƒ ๊ฐ€๋Šฅ (product.nam ๊ฐ™์€ ์‹ค์ˆ˜)
โ€ข ๋Ÿฐํƒ€์ž„์—์„œ์•ผ ์—๋Ÿฌ ๋ฐœ๊ฒฌ
โ€ข ์ž๋™์™„์„ฑ ์—†์Œ
โ€ข ๋ฆฌํŒฉํ† ๋ง ์‹œ ๋ˆ„๋ฝ ๊ฐ€๋Šฅ

ํƒ€์ž… ์ •์˜ ํ›„:
โ€ข ์ปดํŒŒ์ผ ํƒ€์ž„์— ์—๋Ÿฌ ๊ฒ€์ถœ โœ…
โ€ข IDE ์ž๋™์™„์„ฑ ์ง€์› โœ…
โ€ข ์•ˆ์ „ํ•œ ๋ฆฌํŒฉํ† ๋ง โœ…
โ€ข ์ฝ”๋“œ ๊ฐ€๋…์„ฑ ํ–ฅ์ƒ โœ…
์—๋Ÿฌ ์ฒ˜๋ฆฌ์™€ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ํƒ€์ž…

์‹ค์ „์—์„œ๋Š” ์—๋Ÿฌ ์ฒ˜๋ฆฌ๋„ ์ค‘์š”ํ•˜์ง€. `getServerSideProps`๋Š” ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ๋ฐ˜ํ™˜ ํƒ€์ž…์„ ์ง€์›ํ•ด:
export const getServerSideProps: GetServerSideProps<ProductPageProps> = async (context) => {
  try {
    const { id } = context.params as { id: string }
    
    const res = await fetch(`https://api.example.com/products/${id}`)
    
    // 404 ์ฒ˜๋ฆฌ
    if (!res.ok) {
      return {
        notFound: true  // ํƒ€์ž… ์•ˆ์ „ํ•œ 404 ๋ฐ˜ํ™˜
      }
    }
    
    const product: Product = await res.json()
    
    // ์กฐ๊ฑด๋ถ€ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ
    if (!product.inStock) {
      return {
        redirect: {
          destination: '/out-of-stock',
          permanent: false
        }
      }
    }
    
    return {
      props: { product, relatedProducts: [] }
    }
  } catch (error) {
    console.error('๋ฐ์ดํ„ฐ ๋กœ๋”ฉ ์‹คํŒจ:', error)
    return {
      notFound: true
    }
  }
}
`notFound`์™€ `redirect`๋„ ๋ชจ๋‘ ํƒ€์ž…์ด ์ •์˜๋˜์–ด ์žˆ์–ด์„œ ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด! ๐Ÿ˜Š

๐Ÿ’ก ํ”„๋กœ ํŒ: Context ํƒ€์ž… ํ™œ์šฉํ•˜๊ธฐ

`context` ๊ฐ์ฒด์—๋Š” `params`, `query`, `req`, `res` ๋“ฑ ๋‹ค์–‘ํ•œ ์ •๋ณด๊ฐ€ ๋“ค์–ด์žˆ์–ด. ์ด๊ฒƒ๋“ค๋„ ํƒ€์ž…์ด ์ •์˜๋˜์–ด ์žˆ์œผ๋‹ˆ๊นŒ ์ ๊ทน ํ™œ์šฉํ•ด๋ด:

export const getServerSideProps: GetServerSideProps = async (context) => {
  const { req, res, query, params } = context
  
  // ์ฟ ํ‚ค ์ ‘๊ทผ (ํƒ€์ž… ์•ˆ์ „)
  const cookies = req.cookies
  
  // ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ (ํƒ€์ž… ์บ์ŠคํŒ… ํ•„์š”)
  const page = Number(query.page) || 1
  
  // ์ปค์Šคํ…€ ํ—ค๋” ์„ค์ •
  res.setHeader('Cache-Control', 'public, s-maxage=10, stale-while-revalidate=59')
  
  // ...
}

๐Ÿ“ฆ getStaticProps์™€ getStaticPaths ํƒ€์ž… ์ •์˜

SSG(Static Site Generation)๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋Š” `getStaticProps`์™€ `getStaticPaths`๋ฅผ ์“ฐ์ง€? ์ด๊ฒƒ๋“ค๋„ ํƒ€์ž… ์ •์˜๊ฐ€ ์ค‘์š”ํ•ด! ํŠนํžˆ ๋™์  ๋ผ์šฐํŒ…์„ ์‚ฌ์šฉํ•  ๋•Œ๋Š” ๋”๋”์šฑ ๊ทธ๋ž˜. ๐ŸŽฏ

getStaticProps ๊ธฐ๋ณธ ํƒ€์ž…

import type { GetStaticProps, NextPage } from 'next'

interface BlogPost {
  id: string
  title: string
  content: string
  author: string
  publishedAt: string
  tags: string[]
}

interface BlogPageProps {
  posts: BlogPost[]
  totalPages: number
}

export const getStaticProps: GetStaticProps<BlogPageProps> = async () => {
  const res = await fetch('https://api.example.com/posts')
  const posts: BlogPost[] = await res.json()
  
  return {
    props: {
      posts,
      totalPages: Math.ceil(posts.length / 10)
    },
    revalidate: 60  // ISR: 60์ดˆ๋งˆ๋‹ค ์žฌ์ƒ์„ฑ
  }
}

const BlogPage: NextPage<BlogPageProps> = ({ posts, totalPages }) => {
  return (
    <div>
      <h1>๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ ๐Ÿ“</h1>
      {posts.map(post => (
        <article key={post.id}>
          <h2>{post.title}</h2>
          <p>์ž‘์„ฑ์ž: {post.author}</p>
        </article>
      ))}
    </div>
  )
}
`getStaticProps`๋Š” ๋นŒ๋“œ ํƒ€์ž„์— ์‹คํ–‰๋˜๊ธฐ ๋•Œ๋ฌธ์— `context` ๊ฐ์ฒด๊ฐ€ `getServerSideProps`๋ณด๋‹ค ์ œํ•œ์ ์ด์•ผ. ํ•˜์ง€๋งŒ ํƒ€์ž… ์ •์˜ ๋ฐฉ์‹์€ ๊ฑฐ์˜ ๋™์ผํ•ด! ๐Ÿ˜Š

getStaticPaths ํƒ€์ž… ์ •์˜

๋™์  ๋ผ์šฐํŒ…์„ ์‚ฌ์šฉํ•  ๋•Œ๋Š” `getStaticPaths`๊ฐ€ ํ•„์ˆ˜์•ผ. ์ด๊ฒƒ๋„ ํƒ€์ž…์„ ์ œ๋Œ€๋กœ ์ •์˜ํ•ด์•ผ ํ•ด:
import type { GetStaticPaths, GetStaticProps } from 'next'

interface PostParams {
  slug: string
}

interface PostProps {
  post: BlogPost
}

export const getStaticPaths: GetStaticPaths<PostParams> = async () => {
  const res = await fetch('https://api.example.com/posts')
  const posts: BlogPost[] = await res.json()
  
  const paths = posts.map(post => ({
    params: { slug: post.id }
  }))
  
  return {
    paths,
    fallback: 'blocking'  // ๋˜๋Š” true, false
  }
}

export const getStaticProps: GetStaticProps<PostProps, PostParams> = async (context) => {
  const { slug } = context.params!  // params๋Š” ํ•ญ์ƒ ์กด์žฌ
  
  const res = await fetch(`https://api.example.com/posts/${slug}`)
  const post: BlogPost = await res.json()
  
  return {
    props: { post },
    revalidate: 3600  // 1์‹œ๊ฐ„๋งˆ๋‹ค ์žฌ์ƒ์„ฑ
  }
}
์—ฌ๊ธฐ์„œ ์ฃผ๋ชฉํ•  ์ ์€ `GetStaticProps`์ฒ˜๋Ÿผ ๋‘ ๊ฐœ์˜ ์ œ๋„ค๋ฆญ์„ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ๊ฑฐ์•ผ. ์ฒซ ๋ฒˆ์งธ๋Š” props ํƒ€์ž…, ๋‘ ๋ฒˆ์งธ๋Š” params ํƒ€์ž…! ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด `context.params`์˜ ํƒ€์ž…์ด ์ •ํ™•ํ•˜๊ฒŒ ์ถ”๋ก ๋ผ. ๐ŸŽ‰

๐Ÿค” fallback ์˜ต์…˜๋ณ„ ํƒ€์ž… ์ฒ˜๋ฆฌ โ€ข fallback: false
- paths์— ์—†๋Š” ๊ฒฝ๋กœ๋Š” 404
- ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ํƒ€์ž… ์ฒ˜๋ฆฌ

โ€ข fallback: true
- ์ปดํฌ๋„ŒํŠธ์—์„œ ๋กœ๋”ฉ ์ƒํƒœ ์ฒ˜๋ฆฌ ํ•„์š”
- props๊ฐ€ undefined์ผ ์ˆ˜ ์žˆ์Œ
- ํƒ€์ž… ๊ฐ€๋“œ ํ•„์ˆ˜!

โ€ข fallback: 'blocking'
- SSR์ฒ˜๋Ÿผ ๋™์ž‘
- props๋Š” ํ•ญ์ƒ ์กด์žฌ
- ํƒ€์ž… ์ฒ˜๋ฆฌ๊ฐ€ ๊ฐ€์žฅ ๊น”๋”ํ•จ โœ…
fallback: true์ผ ๋•Œ ํƒ€์ž… ์ฒ˜๋ฆฌ

import { useRouter } from 'next/router'

const PostPage: NextPage<PostProps> = ({ post }) => {
  const router = useRouter()
  
  // fallback ์ƒํƒœ ์ฒดํฌ
  if (router.isFallback) {
    return <div>๋กœ๋”ฉ ์ค‘... โณ</div>
  }
  
  // ์ด์ œ post๋Š” ํ™•์‹คํžˆ ์กด์žฌ
  return (
    <article>
      <h1>{post.title}</h1>
      <p>{post.content}</p>
    </article>
  )
}

๐ŸŽญ API ๋ผ์šฐํŠธ ํƒ€์ž… ์ •์˜

Next.js์˜ API ๋ผ์šฐํŠธ๋„ ํƒ€์ž… ์ •์˜๊ฐ€ ๊ฐ€๋Šฅํ•ด! ๋ฐฑ์—”๋“œ API๋ฅผ ๋งŒ๋“ค ๋•Œ ํƒ€์ž… ์•ˆ์ •์„ฑ์„ ํ™•๋ณดํ•˜๋Š” ๊ฑด ์ •๋ง ์ค‘์š”ํ•˜๊ฑฐ๋“ . ๐Ÿ”

๊ธฐ๋ณธ API ํ•ธ๋“ค๋Ÿฌ ํƒ€์ž…

import type { NextApiRequest, NextApiResponse } from 'next'

interface UserResponse {
  id: string
  name: string
  email: string
}

interface ErrorResponse {
  error: string
  message: string
}

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse<UserResponse | ErrorResponse>
) {
  if (req.method !== 'GET') {
    return res.status(405).json({ 
      error: 'Method Not Allowed',
      message: 'GET ์š”์ฒญ๋งŒ ํ—ˆ์šฉ๋ฉ๋‹ˆ๋‹ค'
    })
  }
  
  try {
    const { id } = req.query
    
    if (!id || typeof id !== 'string') {
      return res.status(400).json({
        error: 'Bad Request',
        message: 'ID๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค'
      })
    }
    
    const user: UserResponse = {
      id,
      name: 'ํ™๊ธธ๋™',
      email: 'hong@example.com'
    }
    
    return res.status(200).json(user)
  } catch (error) {
    return res.status(500).json({
      error: 'Internal Server Error',
      message: '์„œ๋ฒ„ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค'
    })
  }
}
`NextApiResponse`์ฒ˜๋Ÿผ ์œ ๋‹ˆ์˜จ ํƒ€์ž…์„ ์‚ฌ์šฉํ•˜๋ฉด ์„ฑ๊ณต/์‹คํŒจ ์‘๋‹ต์„ ๋ชจ๋‘ ํƒ€์ž… ์•ˆ์ „ํ•˜๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด! ๐Ÿ˜Š

์ œ๋„ค๋ฆญ API ํ•ธ๋“ค๋Ÿฌ ๋งŒ๋“ค๊ธฐ

์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ํƒ€์ž…์„ ๋งŒ๋“ค๋ฉด ๋” ํŽธํ•ด:
type ApiResponse<T> = {
  success: true
  data: T
} | {
  success: false
  error: string
  message: string
}

interface CreateUserRequest {
  name: string
  email: string
  password: string
}

interface CreateUserData {
  id: string
  name: string
  email: string
  createdAt: string
}

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse<ApiResponse<CreateUserData>>
) {
  if (req.method !== 'POST') {
    return res.status(405).json({
      success: false,
      error: 'Method Not Allowed',
      message: 'POST ์š”์ฒญ๋งŒ ํ—ˆ์šฉ๋ฉ๋‹ˆ๋‹ค'
    })
  }
  
  try {
    const body = req.body as CreateUserRequest
    
    // ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ
    if (!body.name || !body.email || !body.password) {
      return res.status(400).json({
        success: false,
        error: 'Validation Error',
        message: '๋ชจ๋“  ํ•„๋“œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”'
      })
    }
    
    // ์‚ฌ์šฉ์ž ์ƒ์„ฑ ๋กœ์ง...
    const newUser: CreateUserData = {
      id: 'user_123',
      name: body.name,
      email: body.email,
      createdAt: new Date().toISOString()
    }
    
    return res.status(201).json({
      success: true,
      data: newUser
    })
  } catch (error) {
    return res.status(500).json({
      success: false,
      error: 'Internal Server Error',
      message: '์„œ๋ฒ„ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค'
    })
  }
}
์ด๋ ‡๊ฒŒ `ApiResponse` ์ œ๋„ค๋ฆญ ํƒ€์ž…์„ ๋งŒ๋“ค์–ด๋‘๋ฉด ๋ชจ๋“  API ์—”๋“œํฌ์ธํŠธ์—์„œ ์ผ๊ด€๋œ ์‘๋‹ต ํ˜•์‹์„ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ์–ด! ๐ŸŽฏ

๐Ÿ’ก ๋ฏธ๋“ค์›จ์–ด ํƒ€์ž… ์ •์˜

API ๋ผ์šฐํŠธ์—์„œ ๋ฏธ๋“ค์›จ์–ด๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋„ ํƒ€์ž…์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ์–ด:

type Middleware = (
  req: NextApiRequest,
  res: NextApiResponse,
  next: () => void
) => void

const authMiddleware: Middleware = (req, res, next) => {
  const token = req.headers.authorization
  
  if (!token) {
    res.status(401).json({ error: 'Unauthorized' })
    return
  }
  
  // ํ† ํฐ ๊ฒ€์ฆ ๋กœ์ง...
  next()
}

๐Ÿ”ง ๊ณ ๊ธ‰ ํƒ€์ž… ํŒจํ„ด๊ณผ ์ตœ์ ํ™” ๊ธฐ๋ฒ•

์ž, ์ด์ œ ์ข€ ๋” ๊ณ ๊ธ‰ ๊ธฐ๋ฒ•๋“ค์„ ์•Œ์•„๋ณด์ž! ์‹ค์ „์—์„œ ์ •๋ง ์œ ์šฉํ•œ ํŒจํ„ด๋“ค์ด์•ผ. ๐Ÿš€

1. ํƒ€์ž… ์ถ”๋ก  ํ™œ์šฉํ•˜๊ธฐ

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์˜ ๊ฐ•๋ ฅํ•œ ํƒ€์ž… ์ถ”๋ก ์„ ํ™œ์šฉํ•˜๋ฉด ์ฝ”๋“œ๊ฐ€ ํ›จ์”ฌ ๊น”๋”ํ•ด์ ธ:
// โŒ ๋ถˆํ•„์š”ํ•œ ํƒ€์ž… ๋ช…์‹œ
const getUser = async (id: string): Promise<UserResponse> => {
  const res: Response = await fetch(`/api/users/${id}`)
  const data: UserResponse = await res.json()
  return data
}

// โœ… ํƒ€์ž… ์ถ”๋ก  ํ™œ์šฉ
const getUser = async (id: string) => {
  const res = await fetch(`/api/users/${id}`)
  const data: UserResponse = await res.json()
  return data  // ๋ฐ˜ํ™˜ ํƒ€์ž… ์ž๋™ ์ถ”๋ก 
}
ํ•„์š”ํ•œ ๊ณณ์—๋งŒ ํƒ€์ž…์„ ๋ช…์‹œํ•˜๊ณ , ๋‚˜๋จธ์ง€๋Š” ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์•Œ์•„์„œ ์ถ”๋ก ํ•˜๊ฒŒ ํ•˜๋Š” ๊ฒŒ ์ข‹์•„! ๐Ÿ˜Š

2. ์œ ํ‹ธ๋ฆฌํ‹ฐ ํƒ€์ž… ํ™œ์šฉ

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์˜ ์œ ํ‹ธ๋ฆฌํ‹ฐ ํƒ€์ž…๋“ค์„ ์ ๊ทน ํ™œ์šฉํ•ด๋ด:
interface User {
  id: string
  name: string
  email: string
  password: string
  createdAt: string
  updatedAt: string
}

// ๋น„๋ฐ€๋ฒˆํ˜ธ ์ œ์™ธํ•œ ๊ณต๊ฐœ ์ •๋ณด
type PublicUser = Omit<User, 'password'>

// ์—…๋ฐ์ดํŠธ ๊ฐ€๋Šฅํ•œ ํ•„๋“œ๋งŒ
type UpdateUserInput = Partial<Pick<User, 'name' | 'email'>>

// ์ฝ๊ธฐ ์ „์šฉ ์‚ฌ์šฉ์ž
type ReadonlyUser = Readonly<User>

// ํ•„์ˆ˜ ํ•„๋“œ๋งŒ
type RequiredUser = Required<Pick<User, 'id' | 'name' | 'email'>>
์ด๋Ÿฐ ์œ ํ‹ธ๋ฆฌํ‹ฐ ํƒ€์ž…๋“ค์„ ์กฐํ•ฉํ•˜๋ฉด ์ •๋ง ๊ฐ•๋ ฅํ•œ ํƒ€์ž… ์‹œ์Šคํ…œ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด! ๐ŸŽจ

3. ์กฐ๊ฑด๋ถ€ ํƒ€์ž…์œผ๋กœ ์œ ์—ฐ์„ฑ ํ™•๋ณด

type ApiResult<T, E = Error> = 
  | { status: 'success'; data: T }
  | { status: 'error'; error: E }
  | { status: 'loading' }

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const fetchData = async <T>(url: string): Promise<ApiResult<T>> => {
  try {
    const res = await fetch(url)
    const data = await res.json()
    return { status: 'success', data }
  } catch (error) {
    return { status: 'error', error: error as Error }
  }
}

// ํƒ€์ž… ๊ฐ€๋“œ์™€ ํ•จ๊ป˜ ์‚ฌ์šฉ
const result = await fetchData<User[]>('/api/users')

if (result.status === 'success') {
  // result.data๋Š” User[] ํƒ€์ž…
  console.log(result.data.length)
} else if (result.status === 'error') {
  // result.error๋Š” Error ํƒ€์ž…
  console.error(result.error.message)
}
์กฐ๊ฑด๋ถ€ ํƒ€์ž…๊ณผ ํƒ€์ž… ๊ฐ€๋“œ๋ฅผ ์กฐํ•ฉํ•˜๋ฉด ๋Ÿฐํƒ€์ž„ ์•ˆ์ •์„ฑ์ด ํฌ๊ฒŒ ํ–ฅ์ƒ๋ผ! ๐Ÿ›ก๏ธ

๐ŸŽฏ ์‹ค์ „ ํŒจํ„ด: ํƒ€์ž… ์•ˆ์ „ํ•œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜

ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋„ ํƒ€์ž… ์•ˆ์ „ํ•˜๊ฒŒ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด:
// env.d.ts
declare namespace NodeJS {
  interface ProcessEnv {
    NEXT_PUBLIC_API_URL: string
    DATABASE_URL: string
    JWT_SECRET: string
    NODE_ENV: 'development' | 'production' | 'test'
  }
}

// ์‚ฌ์šฉ
const apiUrl = process.env.NEXT_PUBLIC_API_URL  // ํƒ€์ž… ์•ˆ์ „!
const nodeEnv = process.env.NODE_ENV  // 'development' | 'production' | 'test'
์ด์ œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์˜คํƒ€๋„ ์ปดํŒŒ์ผ ํƒ€์ž„์— ์žก์„ ์ˆ˜ ์žˆ์–ด! ๐ŸŽ‰
4. ์ œ๋„ค๋ฆญ ์ปดํฌ๋„ŒํŠธ ํŒจํ„ด

์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ œ๋„ค๋ฆญ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž:
interface ListProps<T> {
  items: T[]
  renderItem: (item: T, index: number) => React.ReactNode
  keyExtractor: (item: T) => string
  emptyMessage?: string
}

function List<T>({ items, renderItem, keyExtractor, emptyMessage }: ListProps<T>) {
  if (items.length === 0) {
    return <div>{emptyMessage || 'ํ•ญ๋ชฉ์ด ์—†์Šต๋‹ˆ๋‹ค'}</div>
  }
  
  return (
    <div>
      {items.map((item, index) => (
        <div key={keyExtractor(item)}>
          {renderItem(item, index)}
        </div>
      ))}
    </div>
  )
}

// ์‚ฌ์šฉ
<List
  items={users}
  renderItem={(user) => <UserCard user={user} />}
  keyExtractor={(user) => user.id}
  emptyMessage="์‚ฌ์šฉ์ž๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค"
/>
์ œ๋„ค๋ฆญ ์ปดํฌ๋„ŒํŠธ๋Š” ํƒ€์ž… ์•ˆ์ •์„ฑ์„ ์œ ์ง€ํ•˜๋ฉด์„œ๋„ ์žฌ์‚ฌ์šฉ์„ฑ์„ ๊ทน๋Œ€ํ™”ํ•ด์ค˜! ๐Ÿ”„

ํƒ€์ž… ์‹œ์Šคํ…œ ์ตœ์ ํ™” ์ „๋žต 1 ํƒ€์ž… ์ถ”๋ก  ๋ถˆํ•„์š”ํ•œ ํƒ€์ž… ๋ช…์‹œ ์ œ๊ฑฐ โœ“ ์ฝ”๋“œ ๊ฐ„๊ฒฐํ™” 2 ์œ ํ‹ธ๋ฆฌํ‹ฐ ํƒ€์ž… Partial, Pick, Omit ํ™œ์šฉ โœ“ ์žฌ์‚ฌ์šฉ์„ฑ ์ฆ๊ฐ€ 3 ์กฐ๊ฑด๋ถ€ ํƒ€์ž… ํƒ€์ž… ๊ฐ€๋“œ์™€ ํ•จ๊ป˜ ์‚ฌ์šฉ โœ“ ์•ˆ์ •์„ฑ ํ–ฅ์ƒ 4 ์ œ๋„ค๋ฆญ ํŒจํ„ด ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ปดํฌ๋„ŒํŠธ ์„ค๊ณ„ โœ“ ์œ ์—ฐ์„ฑ ํ™•๋ณด 5 ํƒ€์ž… ๊ฐ€๋“œ ๋Ÿฐํƒ€์ž„ ํƒ€์ž… ์ฒดํฌ ๊ฐ•ํ™” โœ“ ์˜ค๋ฅ˜ ๋ฐฉ์ง€ ํ†ตํ•ฉ๋œ ํƒ€์ž… ์‹œ์Šคํ…œ์œผ๋กœ ์•ˆ์ •์ ์ธ SSR ๊ตฌํ˜„

โšก ์„ฑ๋Šฅ ์ตœ์ ํ™”์™€ ํƒ€์ž… ์‹œ์Šคํ…œ

ํƒ€์ž… ์‹œ์Šคํ…œ์ด ์„ฑ๋Šฅ์—๋„ ์˜ํ–ฅ์„ ์ค„ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฑฐ ์•Œ๊ณ  ์žˆ์–ด? ํŠนํžˆ ๋Œ€๊ทœ๋ชจ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ํƒ€์ž… ์ฒดํฌ ์‹œ๊ฐ„์ด ๋นŒ๋“œ ์‹œ๊ฐ„์— ํฐ ์˜ํ–ฅ์„ ๋ฏธ์ณ. ์ตœ์ ํ™” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์ž! ๐Ÿš€

1. ํƒ€์ž… ์ž„ํฌํŠธ ์ตœ์ ํ™”

ํƒ€์ž…๋งŒ ์ž„ํฌํŠธํ•  ๋•Œ๋Š” `type` ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด:
// โŒ ๋Ÿฐํƒ€์ž„ ์ฝ”๋“œ๋„ ํ•จ๊ป˜ ๋ฒˆ๋“ค๋ง
import { User, Product } from './types'

// โœ… ํƒ€์ž…๋งŒ ์ž„ํฌํŠธ (๋ฒˆ๋“ค ํฌ๊ธฐ ๊ฐ์†Œ)
import type { User, Product } from './types'

// ํ˜ผํ•ฉ ์‚ฌ์šฉ
import { fetchUser, type User } from './api'
์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ํƒ€์ž… ์ •๋ณด๋Š” ์ปดํŒŒ์ผ ํƒ€์ž„์—๋งŒ ์‚ฌ์šฉ๋˜๊ณ  ๋Ÿฐํƒ€์ž„ ๋ฒˆ๋“ค์—๋Š” ํฌํ•จ๋˜์ง€ ์•Š์•„! ๋ฒˆ๋“ค ํฌ๊ธฐ๊ฐ€ ์ค„์–ด๋“ค์–ด. ๐Ÿ“ฆ

2. ํƒ€์ž… ์ฒดํฌ ๋ฒ”์œ„ ์ œํ•œ

`tsconfig.json`์—์„œ ๋ถˆํ•„์š”ํ•œ ํŒŒ์ผ ์ฒดํฌ๋ฅผ ์ œ์™ธํ•ด:
{
  "compilerOptions": {
    "strict": true,
    "skipLibCheck": true  // node_modules ํƒ€์ž… ์ฒดํฌ ์Šคํ‚ต
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules",
    ".next",
    "out",
    "public"
  ]
}
`skipLibCheck: true`๋Š” ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ํƒ€์ž… ์ •์˜ ํŒŒ์ผ ์ฒดํฌ๋ฅผ ๊ฑด๋„ˆ๋›ฐ์–ด์„œ ์ปดํŒŒ์ผ ์†๋„๋ฅผ ํฌ๊ฒŒ ํ–ฅ์ƒ์‹œ์ผœ! โšก

3. ์ฆ๋ถ„ ์ปดํŒŒ์ผ ํ™œ์šฉ

{
  "compilerOptions": {
    "incremental": true,
    "tsBuildInfoFile": ".tsbuildinfo"
  }
}
์ฆ๋ถ„ ์ปดํŒŒ์ผ์„ ํ™œ์„ฑํ™”ํ•˜๋ฉด ๋ณ€๊ฒฝ๋œ ํŒŒ์ผ๋งŒ ๋‹ค์‹œ ์ปดํŒŒ์ผํ•ด์„œ ๋นŒ๋“œ ์‹œ๊ฐ„์ด ๋‹จ์ถ•๋ผ! ๐ŸŽฏ

โš ๏ธ ์ฃผ์˜: any ํƒ€์ž… ๋‚จ์šฉ ๊ธˆ์ง€

์„ฑ๋Šฅ์„ ์œ„ํ•ด `any` ํƒ€์ž…์„ ๋‚จ์šฉํ•˜๋ฉด ์•ˆ ๋ผ! ํƒ€์ž… ์•ˆ์ •์„ฑ์„ ์žƒ์œผ๋ฉด ๋‚˜์ค‘์— ๋” ํฐ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ฒจ. ๋Œ€์‹  `unknown` ํƒ€์ž…์„ ์‚ฌ์šฉํ•˜๊ณ  ํƒ€์ž… ๊ฐ€๋“œ๋กœ ์ขํ˜€๋‚˜๊ฐ€๋Š” ๊ฒŒ ์ข‹์•„:

// โŒ ํƒ€์ž… ์•ˆ์ •์„ฑ ์ƒ์‹ค
const data: any = await fetchData()

// โœ… ์•ˆ์ „ํ•œ ๋ฐฉ๋ฒ•
const data: unknown = await fetchData()
if (isValidData(data)) {
  // ์ด์ œ data๋Š” ๊ฒ€์ฆ๋œ ํƒ€์ž…
  console.log(data.name)
}
4. ํƒ€์ž… ๋ณ„์นญ vs ์ธํ„ฐํŽ˜์ด์Šค

์„ฑ๋Šฅ ์ฐจ์ด๋Š” ๋ฏธ๋ฏธํ•˜์ง€๋งŒ, ์‚ฌ์šฉ ํŒจํ„ด์— ๋”ฐ๋ผ ์„ ํƒํ•ด:
// ์ธํ„ฐํŽ˜์ด์Šค: ํ™•์žฅ ๊ฐ€๋Šฅ, ์„ ์–ธ ๋ณ‘ํ•ฉ ์ง€์›
interface User {
  id: string
  name: string
}

interface User {  // ์„ ์–ธ ๋ณ‘ํ•ฉ
  email: string
}

// ํƒ€์ž… ๋ณ„์นญ: ์œ ๋‹ˆ์˜จ, ๊ต์ฐจ ํƒ€์ž… ๋“ฑ ๋ณต์žกํ•œ ํƒ€์ž… ํ‘œํ˜„
type Status = 'pending' | 'approved' | 'rejected'
type ApiResponse<T> = { data: T } | { error: string }
์ผ๋ฐ˜์ ์œผ๋กœ ๊ฐ์ฒด ํƒ€์ž…์€ ์ธํ„ฐํŽ˜์ด์Šค, ์œ ๋‹ˆ์˜จ์ด๋‚˜ ๋ณต์žกํ•œ ํƒ€์ž…์€ ํƒ€์ž… ๋ณ„์นญ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒŒ ์ข‹์•„! ๐Ÿ˜Š

๐Ÿ” ์‹ค์ „ ๋””๋ฒ„๊น…๊ณผ ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ…

ํƒ€์ž… ์—๋Ÿฌ๋ฅผ ๋งŒ๋‚ฌ์„ ๋•Œ ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐํ•˜๋Š”์ง€ ์‹ค์ „ ํŒ์„ ์•Œ๋ ค์ค„๊ฒŒ! ๐Ÿ› ๏ธ

1. ํƒ€์ž… ์—๋Ÿฌ ์ฝ๋Š” ๋ฒ•

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋Š” ์ฒ˜์Œ์—” ๋ณต์žกํ•ด ๋ณด์ด์ง€๋งŒ, ํŒจํ„ด์„ ์•Œ๋ฉด ์‰ฌ์›Œ:
// ์—๋Ÿฌ ์˜ˆ์‹œ
Type '{ name: string; age: number; }' is not assignable to type 'User'.
  Property 'email' is missing in type '{ name: string; age: number; }' 
  but required in type 'User'.
์ด ์—๋Ÿฌ๋Š” `User` ํƒ€์ž…์— ํ•„์š”ํ•œ `email` ์†์„ฑ์ด ์—†๋‹ค๋Š” ๋œป์ด์•ผ. ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์€:

โ€ข `email` ์†์„ฑ ์ถ”๊ฐ€ํ•˜๊ธฐ
โ€ข `User` ํƒ€์ž…์—์„œ `email`์„ ์„ ํƒ์ ์œผ๋กœ ๋งŒ๋“ค๊ธฐ (`email?: string`)
โ€ข `Partial` ์‚ฌ์šฉํ•˜๊ธฐ

2. ํƒ€์ž… ์ขํžˆ๊ธฐ (Type Narrowing)

function processValue(value: string | number) {
  // โŒ ์—๋Ÿฌ: Property 'toFixed' does not exist on type 'string | number'
  // return value.toFixed(2)
  
  // โœ… ํƒ€์ž… ๊ฐ€๋“œ๋กœ ์ขํžˆ๊ธฐ
  if (typeof value === 'number') {
    return value.toFixed(2)  // ์ด์ œ value๋Š” number
  }
  return value.toUpperCase()  // ์—ฌ๊ธฐ์„œ value๋Š” string
}

// ์ปค์Šคํ…€ ํƒ€์ž… ๊ฐ€๋“œ
function isUser(obj: any): obj is User {
  return obj && typeof obj.id === 'string' && typeof obj.name === 'string'
}

const data: unknown = await fetchData()
if (isUser(data)) {
  console.log(data.name)  // ํƒ€์ž… ์•ˆ์ „!
}
ํƒ€์ž… ๊ฐ€๋“œ๋Š” ๋Ÿฐํƒ€์ž„ ์ฒดํฌ์™€ ํƒ€์ž… ์ฒดํฌ๋ฅผ ๋™์‹œ์— ํ•ด๊ฒฐํ•ด์ค˜! ๐ŸŽฏ

3. ์ œ๋„ค๋ฆญ ํƒ€์ž… ์—๋Ÿฌ ํ•ด๊ฒฐ

// โŒ ์—๋Ÿฌ ๋ฐœ์ƒ
function getProperty(obj: object, key: string) {
  return obj[key]  // Element implicitly has an 'any' type
}

// โœ… ์ œ๋„ค๋ฆญ์œผ๋กœ ํ•ด๊ฒฐ
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
  return obj[key]  // ํƒ€์ž… ์•ˆ์ „!
}

const user = { id: '1', name: 'John' }
const name = getProperty(user, 'name')  // string ํƒ€์ž…์œผ๋กœ ์ถ”๋ก 
// const invalid = getProperty(user, 'invalid')  // ์ปดํŒŒ์ผ ์—๋Ÿฌ!
`keyof`์™€ ์ œ๋„ค๋ฆญ์„ ์กฐํ•ฉํ•˜๋ฉด ๊ฐ์ฒด ์†์„ฑ ์ ‘๊ทผ๋„ ํƒ€์ž… ์•ˆ์ „ํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ์–ด! ๐Ÿ”

๐Ÿ’ก VSCode ํ™œ์šฉ ํŒ โ€ข ๋ณ€์ˆ˜์— ๋งˆ์šฐ์Šค ์˜ฌ๋ฆฌ๋ฉด ์ถ”๋ก ๋œ ํƒ€์ž… ํ™•์ธ ๊ฐ€๋Šฅ
โ€ข `Cmd/Ctrl + .`๋กœ ๋น ๋ฅธ ์ˆ˜์ • ์ œ์•ˆ ๋ฐ›๊ธฐ
โ€ข `F12`๋กœ ํƒ€์ž… ์ •์˜๋กœ ์ด๋™
โ€ข `Shift + F12`๋กœ ๋ชจ๋“  ์ฐธ์กฐ ์ฐพ๊ธฐ

์ด๋Ÿฐ ๊ธฐ๋Šฅ๋“ค์„ ์ ๊ทน ํ™œ์šฉํ•˜๋ฉด ๋””๋ฒ„๊น…์ด ํ›จ์”ฌ ์‰ฌ์›Œ์ ธ! ๐ŸŽจ
4. ์„œ๋“œํŒŒํ‹ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํƒ€์ž… ๋ฌธ์ œ

ํƒ€์ž… ์ •์˜๊ฐ€ ์—†๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ:
// types/my-library.d.ts ํŒŒ์ผ ์ƒ์„ฑ
declare module 'my-library' {
  export interface Config {
    apiKey: string
    timeout?: number
  }
  
  export function initialize(config: Config): void
  export function getData(): Promise<any>
}

// ์‚ฌ์šฉ
import { initialize } from 'my-library'
initialize({ apiKey: 'xxx' })  // ํƒ€์ž… ์ฒดํฌ ๋จ!
์ง์ ‘ ํƒ€์ž… ์ •์˜๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ํƒ€์ž…์ด ์—†๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋„ ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด! ๐Ÿ“š

๐ŸŽ“ ์‹ค์ „ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ์™€ ๋ฒ ์ŠคํŠธ ํ”„๋ž™ํ‹ฐ์Šค

์ด์ œ ์‹ค์ „์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ์™€ ๋ฒ ์ŠคํŠธ ํ”„๋ž™ํ‹ฐ์Šค๋ฅผ ์•Œ์•„๋ณด์ž! ๋Œ€๊ทœ๋ชจ ํ”„๋กœ์ ํŠธ์—์„œ๋„ ํƒ€์ž… ์•ˆ์ •์„ฑ์„ ์œ ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด์•ผ. ๐Ÿ—๏ธ

์ถ”์ฒœ ํด๋” ๊ตฌ์กฐ

src/
โ”œโ”€โ”€ pages/              # Next.js ํŽ˜์ด์ง€
โ”‚   โ”œโ”€โ”€ api/           # API ๋ผ์šฐํŠธ
โ”‚   โ”œโ”€โ”€ _app.tsx
โ”‚   โ””โ”€โ”€ index.tsx
โ”œโ”€โ”€ components/         # ์žฌ์‚ฌ์šฉ ์ปดํฌ๋„ŒํŠธ
โ”‚   โ”œโ”€โ”€ common/
โ”‚   โ””โ”€โ”€ features/
โ”œโ”€โ”€ types/             # ํƒ€์ž… ์ •์˜
โ”‚   โ”œโ”€โ”€ api.ts         # API ๊ด€๋ จ ํƒ€์ž…
โ”‚   โ”œโ”€โ”€ models.ts      # ๋ฐ์ดํ„ฐ ๋ชจ๋ธ
โ”‚   โ””โ”€โ”€ index.ts       # ํƒ€์ž… ์žฌexport
โ”œโ”€โ”€ lib/               # ์œ ํ‹ธ๋ฆฌํ‹ฐ ํ•จ์ˆ˜
โ”‚   โ”œโ”€โ”€ api.ts
โ”‚   โ””โ”€โ”€ helpers.ts
โ”œโ”€โ”€ hooks/             # ์ปค์Šคํ…€ ํ›…
โ”œโ”€โ”€ contexts/          # Context API
โ””โ”€โ”€ styles/            # ์Šคํƒ€์ผ
ํƒ€์ž… ์ •์˜ ํŒŒ์ผ ๊ตฌ์กฐํ™”

// types/models.ts
export interface User {
  id: string
  name: string
  email: string
  role: UserRole
  createdAt: string
}

export type UserRole = 'admin' | 'user' | 'guest'

export interface Product {
  id: string
  name: string
  price: number
  category: Category
}

export interface Category {
  id: string
  name: string
  slug: string
}

// types/api.ts
import type { User, Product } from './models'

export interface ApiResponse<T> {
  success: boolean
  data?: T
  error?: string
  message?: string
}

export interface PaginatedResponse<T> {
  items: T[]
  total: number
  page: number
  pageSize: number
  hasMore: boolean
}

export type GetUsersResponse = ApiResponse<PaginatedResponse<User>>
export type GetProductResponse = ApiResponse<Product>

// types/index.ts (์ค‘์•™ ์ง‘์ค‘์‹ export)
export * from './models'
export * from './api'
์ด๋ ‡๊ฒŒ ํƒ€์ž…์„ ์ฒด๊ณ„์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๋ฉด ํ”„๋กœ์ ํŠธ๊ฐ€ ์ปค์ ธ๋„ ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์‰ฌ์›Œ! ๐ŸŽฏ

API ํด๋ผ์ด์–ธํŠธ ํƒ€์ž… ์•ˆ์ „ํ•˜๊ฒŒ ๋งŒ๋“ค๊ธฐ

// lib/api.ts
import type { ApiResponse, GetUsersResponse, GetProductResponse } from '@/types'

class ApiClient {
  private baseUrl: string
  
  constructor(baseUrl: string) {
    this.baseUrl = baseUrl
  }
  
  private async request<T>(
    endpoint: string,
    options?: RequestInit
  ): Promise<ApiResponse<T>> {
    try {
      const res = await fetch(`${this.baseUrl}${endpoint}`, {
        headers: {
          'Content-Type': 'application/json',
          ...options?.headers
        },
        ...options
      })
      
      if (!res.ok) {
        return {
          success: false,
          error: `HTTP ${res.status}`,
          message: res.statusText
        }
      }
      
      const data = await res.json()
      return {
        success: true,
        data
      }
    } catch (error) {
      return {
        success: false,
        error: 'Network Error',
        message: error instanceof Error ? error.message : 'Unknown error'
      }
    }
  }
  
  async getUsers(page: number = 1): Promise<GetUsersResponse> {
    return this.request(`/users?page=${page}`)
  }
  
  async getProduct(id: string): Promise<GetProductResponse> {
    return this.request(`/products/${id}`)
  }
  
  async createUser(data: CreateUserInput): Promise<ApiResponse<User>> {
    return this.request('/users', {
      method: 'POST',
      body: JSON.stringify(data)
    })
  }
}

export const api = new ApiClient(process.env.NEXT_PUBLIC_API_URL!)

// ์‚ฌ์šฉ
const result = await api.getUsers(1)
if (result.success && result.data) {
  console.log(result.data.items)  // ํƒ€์ž… ์•ˆ์ „!
}
์ด๋Ÿฐ ์‹์œผ๋กœ API ํด๋ผ์ด์–ธํŠธ๋ฅผ ๋งŒ๋“ค๋ฉด ๋ชจ๋“  API ํ˜ธ์ถœ์ด ํƒ€์ž… ์•ˆ์ „ํ•ด์ ธ! ๐Ÿ”

๐ŸŽจ ์ปค์Šคํ…€ ํ›… ํƒ€์ž… ์ •์˜

// hooks/useUser.ts
import { useState, useEffect } from 'react'
import type { User, ApiResponse } from '@/types'
import { api } from '@/lib/api'

interface UseUserResult {
  user: User | null
  loading: boolean
  error: string | null
  refetch: () => Promise<void>
}

export function useUser(userId: string): UseUserResult {
  const [user, setUser] = useState<User | null>(null)
  const [loading, setLoading] = useState(true)
  const [error, setError] = useState<string | null>(null)
  
  const fetchUser = async () => {
    setLoading(true)
    setError(null)
    
    const result = await api.getUser(userId)
    
    if (result.success && result.data) {
      setUser(result.data)
    } else {
      setError(result.error || 'Unknown error')
    }
    
    setLoading(false)
  }
  
  useEffect(() => {
    fetchUser()
  }, [userId])
  
  return { user, loading, error, refetch: fetchUser }
}

// ์‚ฌ์šฉ
const { user, loading, error } = useUser('123')
if (user) {
  console.log(user.name)  // ํƒ€์ž… ์•ˆ์ „!
}
์ปค์Šคํ…€ ํ›…๋„ ๋ฐ˜ํ™˜ ํƒ€์ž…์„ ๋ช…ํ™•ํžˆ ์ •์˜ํ•˜๋ฉด ์‚ฌ์šฉํ•˜๊ธฐ ํŽธํ•ด์ ธ! ๐ŸŽฃ
Context API ํƒ€์ž… ์ •์˜

// contexts/AuthContext.tsx
import { createContext, useContext, useState, ReactNode } from 'react'
import type { User } from '@/types'

interface AuthContextValue {
  user: User | null
  login: (email: string, password: string) => Promise<void>
  logout: () => void
  isAuthenticated: boolean
}

const AuthContext = createContext<AuthContextValue | undefined>(undefined)

interface AuthProviderProps {
  children: ReactNode
}

export function AuthProvider({ children }: AuthProviderProps) {
  const [user, setUser] = useState<User | null>(null)
  
  const login = async (email: string, password: string) => {
    // ๋กœ๊ทธ์ธ ๋กœ์ง...
    const userData: User = { /* ... */ }
    setUser(userData)
  }
  
  const logout = () => {
    setUser(null)
  }
  
  const value: AuthContextValue = {
    user,
    login,
    logout,
    isAuthenticated: user !== null
  }
  
  return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>
}

export function useAuth(): AuthContextValue {
  const context = useContext(AuthContext)
  if (context === undefined) {
    throw new Error('useAuth must be used within AuthProvider')
  }
  return context
}

// ์‚ฌ์šฉ
const { user, login, isAuthenticated } = useAuth()  // ํƒ€์ž… ์•ˆ์ „!
Context๋„ ํƒ€์ž…์„ ์ œ๋Œ€๋กœ ์ •์˜ํ•˜๋ฉด ์ „์—ญ ์ƒํƒœ ๊ด€๋ฆฌ๊ฐ€ ํ›จ์”ฌ ์•ˆ์ „ํ•ด์ ธ! ๐ŸŒ

๐Ÿš€ Next.js 13+ App Router์™€ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ

Next.js 13๋ถ€ํ„ฐ ๋„์ž…๋œ App Router๋Š” ํƒ€์ž… ์‹œ์Šคํ…œ์ด ์กฐ๊ธˆ ๋‹ฌ๋ผ. ์ตœ์‹  ํŒจํ„ด์„ ์•Œ์•„๋ณด์ž! ๐Ÿ†•

์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ ํƒ€์ž… ์ •์˜

// app/users/page.tsx
import type { Metadata } from 'next'

interface User {
  id: string
  name: string
  email: string
}

// ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ export (ํƒ€์ž… ์•ˆ์ „)
export const metadata: Metadata = {
  title: '์‚ฌ์šฉ์ž ๋ชฉ๋ก',
  description: '๋ชจ๋“  ์‚ฌ์šฉ์ž๋ฅผ ํ™•์ธํ•˜์„ธ์š”'
}

// ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋Š” async ๊ฐ€๋Šฅ
export default async function UsersPage() {
  const res = await fetch('https://api.example.com/users', {
    cache: 'no-store'  // SSR
  })
  const users: User[] = await res.json()
  
  return (
    <div>
      <h1>์‚ฌ์šฉ์ž ๋ชฉ๋ก</h1>
      {users.map(user => (
        <div key={user.id}>{user.name}</div>
      ))}
    </div>
  )
}
App Router์—์„œ๋Š” ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๊ธฐ๋ณธ์ด๋ผ `async/await`๋ฅผ ์ง์ ‘ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด! ๐Ÿ˜Š

๋™์  ๋ผ์šฐํŠธ ํƒ€์ž… ์ •์˜

// app/users/[id]/page.tsx
interface PageProps {
  params: { id: string }
  searchParams: { [key: string]: string | string[] | undefined }
}

export default async function UserDetailPage({ params, searchParams }: PageProps) {
  const { id } = params
  const { tab = 'profile' } = searchParams
  
  const res = await fetch(`https://api.example.com/users/${id}`)
  const user: User = await res.json()
  
  return (
    <div>
      <h1>{user.name}</h1>
      <p>ํ˜„์žฌ ํƒญ: {tab}</p>
    </div>
  )
}

// generateStaticParams๋กœ ์ •์  ์ƒ์„ฑ
export async function generateStaticParams() {
  const res = await fetch('https://api.example.com/users')
  const users: User[] = await res.json()
  
  return users.map(user => ({
    id: user.id
  }))
}
`params`์™€ `searchParams`์˜ ํƒ€์ž…์ด ๋ช…ํ™•ํ•˜๊ฒŒ ์ •์˜๋˜์–ด ์žˆ์–ด! ๐ŸŽฏ

ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ ํƒ€์ž…

// app/components/Counter.tsx
'use client'

import { useState } from 'react'

interface CounterProps {
  initialCount?: number
  step?: number
  onCountChange?: (count: number) => void
}

export default function Counter({ 
  initialCount = 0, 
  step = 1,
  onCountChange 
}: CounterProps) {
  const [count, setCount] = useState(initialCount)
  
  const increment = () => {
    const newCount = count + step
    setCount(newCount)
    onCountChange?.(newCount)
  }
  
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={increment}>+{step}</button>
    </div>
  )
}
ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋Š” `'use client'` ์ง€์‹œ์–ด๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ , ์ผ๋ฐ˜ React ์ปดํฌ๋„ŒํŠธ์ฒ˜๋Ÿผ ํƒ€์ž…์„ ์ •์˜ํ•˜๋ฉด ๋ผ! ๐Ÿ“ฑ

๐Ÿ’ก ์„œ๋ฒ„ vs ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ ์„ ํƒ ๊ฐ€์ด๋“œ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ ์‚ฌ์šฉ:
โ€ข ๋ฐ์ดํ„ฐ ํŽ˜์นญ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ
โ€ข ๋ฐฑ์—”๋“œ ๋ฆฌ์†Œ์Šค ์ง์ ‘ ์ ‘๊ทผ
โ€ข ๋ฏผ๊ฐํ•œ ์ •๋ณด ์ฒ˜๋ฆฌ
โ€ข SEO๊ฐ€ ์ค‘์š”ํ•œ ์ฝ˜ํ…์ธ 

ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ ์‚ฌ์šฉ:
โ€ข ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒํ•œ UI
โ€ข ๋ธŒ๋ผ์šฐ์ € API ์‚ฌ์šฉ (localStorage ๋“ฑ)
โ€ข ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ํ•„์š”
โ€ข useState, useEffect ๋“ฑ ํ›… ์‚ฌ์šฉ

๊ธฐ๋ณธ์€ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ, ํ•„์š”ํ•  ๋•Œ๋งŒ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ! ๐ŸŽจ
Route Handler ํƒ€์ž… ์ •์˜

// app/api/users/route.ts
import { NextRequest, NextResponse } from 'next/server'
import type { User } from '@/types'

export async function GET(request: NextRequest) {
  const searchParams = request.nextUrl.searchParams
  const page = Number(searchParams.get('page')) || 1
  
  try {
    const res = await fetch(`https://api.example.com/users?page=${page}`)
    const users: User[] = await res.json()
    
    return NextResponse.json({
      success: true,
      data: users
    })
  } catch (error) {
    return NextResponse.json(
      { success: false, error: 'Failed to fetch users' },
      { status: 500 }
    )
  }
}

export async function POST(request: NextRequest) {
  try {
    const body: CreateUserInput = await request.json()
    
    // ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ
    if (!body.name || !body.email) {
      return NextResponse.json(
        { success: false, error: 'Missing required fields' },
        { status: 400 }
      )
    }
    
    // ์‚ฌ์šฉ์ž ์ƒ์„ฑ ๋กœ์ง...
    const newUser: User = { /* ... */ }
    
    return NextResponse.json(
      { success: true, data: newUser },
      { status: 201 }
    )
  } catch (error) {
    return NextResponse.json(
      { success: false, error: 'Invalid request body' },
      { status: 400 }
    )
  }
}
App Router์˜ Route Handler๋Š” `NextRequest`์™€ `NextResponse`๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํƒ€์ž… ์•ˆ์ „ํ•˜๊ฒŒ API๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด! ๐Ÿ”

๐ŸŽฏ ์‹ค๋ฌด์—์„œ ์ž์ฃผ ๋งŒ๋‚˜๋Š” ์‹œ๋‚˜๋ฆฌ์˜ค์™€ ํ•ด๊ฒฐ์ฑ…

์‹ค์ œ ํ”„๋กœ์ ํŠธ์—์„œ ์ž์ฃผ ๋งˆ์ฃผ์น˜๋Š” ์ƒํ™ฉ๋“ค๊ณผ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์„ ๊ณต์œ ํ• ๊ฒŒ! ๐Ÿ’ผ

์‹œ๋‚˜๋ฆฌ์˜ค 1: ์™ธ๋ถ€ API ์‘๋‹ต ํƒ€์ž… ๋ถˆ์ผ์น˜

์™ธ๋ถ€ API๊ฐ€ ๋ฌธ์„œ์™€ ๋‹ค๋ฅธ ์‘๋‹ต์„ ๋ณด๋‚ผ ๋•Œ๊ฐ€ ์žˆ์–ด. ์ด๋Ÿด ๋•Œ๋Š”:
// ๋Ÿฐํƒ€์ž„ ๊ฒ€์ฆ ํ•จ์ˆ˜ ์ž‘์„ฑ
function validateUser(data: unknown): data is User {
  if (typeof data !== 'object' || data === null) return false
  
  const obj = data as Record<string, unknown>
  
  return (
    typeof obj.id === 'string' &&
    typeof obj.name === 'string' &&
    typeof obj.email === 'string'
  )
}

// ์‚ฌ์šฉ
export const getServerSideProps: GetServerSideProps = async () => {
  const res = await fetch('https://api.example.com/user')
  const data: unknown = await res.json()
  
  if (!validateUser(data)) {
    return { notFound: true }
  }
  
  // ์ด์ œ data๋Š” User ํƒ€์ž…
  return {
    props: { user: data }
  }
}
๋Ÿฐํƒ€์ž„ ๊ฒ€์ฆ๊ณผ ํƒ€์ž… ๊ฐ€๋“œ๋ฅผ ์กฐํ•ฉํ•˜๋ฉด ์•ˆ์ „ํ•ด! ๐Ÿ›ก๏ธ

์‹œ๋‚˜๋ฆฌ์˜ค 2: ํผ ๋ฐ์ดํ„ฐ ํƒ€์ž… ์•ˆ์ „ํ•˜๊ฒŒ ์ฒ˜๋ฆฌ

// Zod ๊ฐ™์€ ์Šคํ‚ค๋งˆ ๊ฒ€์ฆ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํ™œ์šฉ
import { z } from 'zod'

const userSchema = z.object({
  name: z.string().min(2, '์ด๋ฆ„์€ 2์ž ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค'),
  email: z.string().email('์˜ฌ๋ฐ”๋ฅธ ์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•˜์„ธ์š”'),
  age: z.number().min(18, '18์„ธ ์ด์ƒ๋งŒ ๊ฐ€์ž… ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค')
})

type UserFormData = z.infer<typeof userSchema>

export default function SignupForm() {
  const handleSubmit = async (formData: FormData) => {
    const data = {
      name: formData.get('name'),
      email: formData.get('email'),
      age: Number(formData.get('age'))
    }
    
    try {
      const validatedData = userSchema.parse(data)
      // validatedData๋Š” UserFormData ํƒ€์ž…
      await api.createUser(validatedData)
    } catch (error) {
      if (error instanceof z.ZodError) {
        console.error(error.errors)
      }
    }
  }
  
  return <form action={handleSubmit}>{/* ... */}</form>
}
Zod ๊ฐ™์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋Ÿฐํƒ€์ž„ ๊ฒ€์ฆ๊ณผ ํƒ€์ž… ์ถ”๋ก ์„ ๋™์‹œ์— ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์–ด! ๐ŸŽ‰

์‹œ๋‚˜๋ฆฌ์˜ค 3: ๋ณต์žกํ•œ ์ƒํƒœ ๊ด€๋ฆฌ

// Reducer ํƒ€์ž… ์ •์˜
type State = {
  users: User[]
  loading: boolean
  error: string | null
  selectedUserId: string | null
}

type Action =
  | { type: 'FETCH_START' }
  | { type: 'FETCH_SUCCESS'; payload: User[] }
  | { type: 'FETCH_ERROR'; payload: string }
  | { type: 'SELECT_USER'; payload: string }
  | { type: 'CLEAR_SELECTION' }

function userReducer(state: State, action: Action): State {
  switch (action.type) {
    case 'FETCH_START':
      return { ...state, loading: true, error: null }
    case 'FETCH_SUCCESS':
      return { ...state, loading: false, users: action.payload }
    case 'FETCH_ERROR':
      return { ...state, loading: false, error: action.payload }
    case 'SELECT_USER':
      return { ...state, selectedUserId: action.payload }
    case 'CLEAR_SELECTION':
      return { ...state, selectedUserId: null }
    default:
      return state
  }
}

// ์‚ฌ์šฉ
const [state, dispatch] = useReducer(userReducer, initialState)
dispatch({ type: 'FETCH_SUCCESS', payload: users })  // ํƒ€์ž… ์•ˆ์ „!
์œ ๋‹ˆ์˜จ ํƒ€์ž…์œผ๋กœ ์•ก์…˜์„ ์ •์˜ํ•˜๋ฉด dispatchํ•  ๋•Œ ์ž๋™์™„์„ฑ๋„ ๋˜๊ณ  ํƒ€์ž… ์ฒดํฌ๋„ ์™„๋ฒฝํ•ด! ๐ŸŽฏ

๐ŸŒŸ ์žฌ๋Šฅ๋„ท์—์„œ ๋ฐฐ์šฐ๋Š” ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ์ด๋Ÿฐ ๊ณ ๊ธ‰ ํƒ€์ž… ํŒจํ„ด๋“ค์ด ์–ด๋ ต๊ฒŒ ๋А๊ปด์ง„๋‹ค๋ฉด, ์žฌ๋Šฅ๋„ท์—์„œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ์ „๋ฌธ๊ฐ€์—๊ฒŒ 1:1 ๋ฉ˜ํ† ๋ง์„ ๋ฐ›์•„๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์€ ๋ฐฉ๋ฒ•์ด์•ผ! ์‹ค๋ฌด ๊ฒฝํ—˜์ด ํ’๋ถ€ํ•œ ๊ฐœ๋ฐœ์ž๋“ค์ด ํ”„๋กœ์ ํŠธ ์ƒํ™ฉ์— ๋งž๋Š” ๊ตฌ์ฒด์ ์ธ ์กฐ์–ธ์„ ํ•ด์ค„ ๊ฑฐ์•ผ. ํ˜ผ์ž ๊ณ ๋ฏผํ•˜๋Š” ์‹œ๊ฐ„์„ ์ค„์ด๊ณ  ๋น ๋ฅด๊ฒŒ ์„ฑ์žฅํ•  ์ˆ˜ ์žˆ์–ด! ๐Ÿš€
์‹œ๋‚˜๋ฆฌ์˜ค 4: ํƒ€์ž… ์•ˆ์ „ํ•œ ํ™˜๊ฒฝ๋ณ„ ์„ค์ •

// config/index.ts
interface Config {
  apiUrl: string
  apiKey: string
  environment: 'development' | 'staging' | 'production'
  features: {
    analytics: boolean
    debugMode: boolean
  }
}

const configs: Record<Config['environment'], Config> = {
  development: {
    apiUrl: 'http://localhost:3000/api',
    apiKey: 'dev-key',
    environment: 'development',
    features: {
      analytics: false,
      debugMode: true
    }
  },
  staging: {
    apiUrl: 'https://staging-api.example.com',
    apiKey: process.env.STAGING_API_KEY!,
    environment: 'staging',
    features: {
      analytics: true,
      debugMode: true
    }
  },
  production: {
    apiUrl: 'https://api.example.com',
    apiKey: process.env.PRODUCTION_API_KEY!,
    environment: 'production',
    features: {
      analytics: true,
      debugMode: false
    }
  }
}

const env = (process.env.NODE_ENV || 'development') as Config['environment']
export const config: Config = configs[env]

// ์‚ฌ์šฉ
if (config.features.debugMode) {
  console.log('Debug mode enabled')
}
ํ™˜๊ฒฝ๋ณ„ ์„ค์ •๋„ ํƒ€์ž… ์•ˆ์ „ํ•˜๊ฒŒ ๊ด€๋ฆฌํ•˜๋ฉด ๋ฐฐํฌ ์‹ค์ˆ˜๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ์–ด! ๐ŸŽฏ

๐Ÿ“š ๋งˆ๋ฌด๋ฆฌํ•˜๋ฉฐ: ํƒ€์ž… ์‹œ์Šคํ…œ๊ณผ ํ•จ๊ป˜ ์„ฑ์žฅํ•˜๊ธฐ

์ž, ์—ฌ๊ธฐ๊นŒ์ง€ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์™€ Next.js SSR์˜ ํƒ€์ž… ์‹œ์Šคํ…œ ์ตœ์ ํ™”์— ๋Œ€ํ•ด ๊นŠ์ด ์žˆ๊ฒŒ ์•Œ์•„๋ดค์–ด! ์ฒ˜์Œ์—” ๋ณต์žกํ•ด ๋ณด์ด์ง€๋งŒ, ํ•œ ๋ฒˆ ์ต์ˆ™ํ•ด์ง€๋ฉด ํƒ€์ž… ์‹œ์Šคํ…œ ์—†์ด๋Š” ๊ฐœ๋ฐœํ•  ์ˆ˜ ์—†์„ ๊ฑฐ์•ผ. ๐Ÿ˜Š

๐ŸŽ“ ํ•ต์‹ฌ ์š”์•ฝ 1. ๊ธฐ๋ณธ๊ธฐ๊ฐ€ ์ค‘์š”ํ•ด
โ€ข Next.js์˜ ํƒ€์ž… ์ง€์›์„ ์ ๊ทน ํ™œ์šฉํ•˜์ž
โ€ข `GetServerSideProps`, `GetStaticProps` ์ œ๋„ค๋ฆญ ํƒ€์ž… ์ •์˜
โ€ข API ๋ผ์šฐํŠธ๋„ ํƒ€์ž… ์•ˆ์ „ํ•˜๊ฒŒ

2. ๊ณ ๊ธ‰ ํŒจํ„ด ํ™œ์šฉ
โ€ข ์œ ํ‹ธ๋ฆฌํ‹ฐ ํƒ€์ž…์œผ๋กœ ์žฌ์‚ฌ์šฉ์„ฑ ๋†’์ด๊ธฐ
โ€ข ์ œ๋„ค๋ฆญ๊ณผ ์กฐ๊ฑด๋ถ€ ํƒ€์ž…์œผ๋กœ ์œ ์—ฐ์„ฑ ํ™•๋ณด
โ€ข ํƒ€์ž… ๊ฐ€๋“œ๋กœ ๋Ÿฐํƒ€์ž„ ์•ˆ์ •์„ฑ ๊ฐ•ํ™”

3. ์‹ค์ „ ์ตœ์ ํ™”
โ€ข ํƒ€์ž… ์ž„ํฌํŠธ ์ตœ์ ํ™”๋กœ ๋ฒˆ๋“ค ํฌ๊ธฐ ๊ฐ์†Œ
โ€ข ์ฆ๋ถ„ ์ปดํŒŒ์ผ๋กœ ๋นŒ๋“œ ์†๋„ ํ–ฅ์ƒ
โ€ข ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ ์ฒด๊ณ„ํ™”

4. ์ง€์†์ ์ธ ํ•™์Šต
โ€ข ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋Š” ๊ณ„์† ๋ฐœ์ „ํ•˜๊ณ  ์žˆ์–ด
โ€ข ์ปค๋ฎค๋‹ˆํ‹ฐ์™€ ๊ณต์‹ ๋ฌธ์„œ ํ™œ์šฉ
โ€ข ์‹ค์ „ ํ”„๋กœ์ ํŠธ์—์„œ ๊ฒฝํ—˜ ์Œ“๊ธฐ
ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์™€ Next.js์˜ ์กฐํ•ฉ์€ ํ˜„๋Œ€ ์›น ๊ฐœ๋ฐœ์˜ ํ‘œ์ค€์ด ๋˜์–ด๊ฐ€๊ณ  ์žˆ์–ด. ์ดˆ๊ธฐ ํ•™์Šต ๊ณก์„ ์€ ์žˆ์ง€๋งŒ, ์žฅ๊ธฐ์ ์œผ๋กœ ๋ณด๋ฉด ๊ฐœ๋ฐœ ์ƒ์‚ฐ์„ฑ๊ณผ ์ฝ”๋“œ ํ’ˆ์งˆ์„ ํฌ๊ฒŒ ํ–ฅ์ƒ์‹œ์ผœ์ค˜. ๐Ÿš€

ํŠนํžˆ ์„œ๋ฒ„์‚ฌ์ด๋“œ ๋ Œ๋”๋ง ํ™˜๊ฒฝ์—์„œ๋Š” ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„ ์–‘์ชฝ์˜ ํƒ€์ž… ์•ˆ์ •์„ฑ์ด ์ •๋ง ์ค‘์š”ํ•ด. ๋Ÿฐํƒ€์ž„ ์—๋Ÿฌ๋ฅผ ์ปดํŒŒ์ผ ํƒ€์ž„์— ์žก์„ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฑด ์—„์ฒญ๋‚œ ์žฅ์ ์ด๊ฑฐ๋“ ! ๐ŸŽฏ

โš ๏ธ ๋งˆ์ง€๋ง‰ ์กฐ์–ธ ์™„๋ฒฝํ•œ ํƒ€์ž… ์‹œ์Šคํ…œ์„ ์ฒ˜์Œ๋ถ€ํ„ฐ ๋งŒ๋“ค๋ ค๊ณ  ํ•˜์ง€ ๋งˆ! ์ ์ง„์ ์œผ๋กœ ๊ฐœ์„ ํ•ด๋‚˜๊ฐ€๋Š” ๊ฒŒ ์ค‘์š”ํ•ด. ๋จผ์ € ํ•ต์‹ฌ ๊ธฐ๋Šฅ๋ถ€ํ„ฐ ํƒ€์ž…์„ ์ •์˜ํ•˜๊ณ , ํ”„๋กœ์ ํŠธ๊ฐ€ ์„ฑ์žฅํ•˜๋ฉด์„œ ํƒ€์ž… ์‹œ์Šคํ…œ๋„ ํ•จ๊ป˜ ๋ฐœ์ „์‹œ์ผœ๋‚˜๊ฐ€์ž. ๐ŸŒฑ

๊ทธ๋ฆฌ๊ณ  ํŒ€์›๋“ค๊ณผ ํƒ€์ž… ์ปจ๋ฒค์…˜์„ ๊ณต์œ ํ•˜๋Š” ๊ฒƒ๋„ ์žŠ์ง€ ๋ง์ž. ์ผ๊ด€๋œ ํƒ€์ž… ์Šคํƒ€์ผ์ด ์œ ์ง€๋ณด์ˆ˜๋ฅผ ํ›จ์”ฌ ์‰ฝ๊ฒŒ ๋งŒ๋“ค์–ด์ค˜!
ํ˜น์‹œ ๋” ๊นŠ์ด ์žˆ๋Š” ํ•™์Šต์ด๋‚˜ ์‹ค์ „ ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ ์กฐ์–ธ์ด ํ•„์š”ํ•˜๋‹ค๋ฉด, ์žฌ๋Šฅ๋„ท์˜ ์ „๋ฌธ๊ฐ€๋“ค์—๊ฒŒ ๋„์›€์„ ๋ฐ›์•„๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์€ ์„ ํƒ์ด์•ผ. ์‹ค๋ฌด ๊ฒฝํ—˜์ด ํ’๋ถ€ํ•œ ๊ฐœ๋ฐœ์ž๋“ค์ด ๋‹น์‹ ์˜ ํ”„๋กœ์ ํŠธ์— ๋งž๋Š” ์ตœ์ ์˜ ํƒ€์ž… ์‹œ์Šคํ…œ ์„ค๊ณ„๋ฅผ ๋„์™€์ค„ ๊ฑฐ์•ผ! ๐Ÿ’ช

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์™€ Next.js๋กœ ์•ˆ์ „ํ•˜๊ณ  ํ™•์žฅ ๊ฐ€๋Šฅํ•œ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“ค์–ด๋ณด์ž. ์ฒ˜์Œ์—” ์–ด๋ ค์›Œ ๋ณด์—ฌ๋„, ํ•œ ๊ฑธ์Œ์”ฉ ๋‚˜์•„๊ฐ€๋‹ค ๋ณด๋ฉด ์–ด๋А์ƒˆ ํƒ€์ž… ์‹œ์Šคํ…œ์˜ ๋งˆ์Šคํ„ฐ๊ฐ€ ๋˜์–ด ์žˆ์„ ๊ฑฐ์•ผ! ๐ŸŽ‰

ํ–‰๋ณตํ•œ ์ฝ”๋”ฉ ๋˜๊ธธ ๋ฐ”๋ผ! Happy Typing! ๐Ÿš€โœจ

๐Ÿ’ก ์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด, ์‹ค์ „ ํ”„๋กœ์ ํŠธ์— ๋ฐ”๋กœ ์ ์šฉํ•ด๋ณด์„ธ์š”!

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์™€ Next.js๋กœ ๋” ์•ˆ์ „ํ•˜๊ณ  ํ™•์žฅ ๊ฐ€๋Šฅํ•œ ์›น์„ ๋งŒ๋“ค์–ด๊ฐ‘์‹œ๋‹ค! ๐Ÿš€

๋Œ“๊ธ€ ์ž‘์„ฑ

์ด ๊ธ€์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒ๊ฐ์„ ๋“ค๋ ค์ฃผ์„ธ์š”

๋Œ“๊ธ€ 0
๋Œ“๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.

์•„์ง ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค.