Next.js 5

[Next.js] fetch data, React vs Next.js

client component์—์„œ ๊ธฐ์กด์˜ API์™€ ์†Œํ†ตํ•˜๋˜ ๋ฐฉ์‹ useEffect useState -> metadata ์‚ฌ์šฉ ๋ถˆ๊ฐ€ ๋กœ๋”ฉ state ๊ตฌํ˜„ 'use client'; import { useEffect, useState } from 'react'; /* useState์˜ ์‚ฌ์šฉ์œผ๋กœ ์ธํ•ด, ์‚ฌ์šฉ ๋ถˆ๊ฐ€๋Šฅ export const metadata = { title: 'Home', }; */ export default function Page() { const [isLoading, setIsLoading] = useState(true); const [movies, setMovies] = useState([]); //useState -> interactive component๋ฅผ ์‚ฌ์šฉํ•˜๊ฒ ๋‹ค. -> "use c..

Next.js 2024.03.19

[Next.js] Server component vs Client component

์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ vs ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ ์ฒ˜์Œ ๋ฐฑ์—”๋“œ ์„œ๋ฒ„์—์„œ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์™€ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ชจ๋‘ ๋ Œ๋”๋ง ํด๋ผ์ธํŠธ ์ปดํฌ๋„ŒํŠธ๋งŒ ํ”„๋ก ํŠธ์—”๋“œ์—์„œ ๋‹ค์‹œ ๋ Œ๋”๋ง, ๋‹ค์‹œ hydrated(activate) ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ๋‹ค์šด๋กœ๋“œํ•˜์—ฌ ์‹คํ–‰ํ•˜๊ณ , ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ๋‹ค์šด๋กœ๋“œ X ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ๋Š” ๋”ฑ ํ•œ๋ฒˆ๋งŒ ์„œ๋ฒ„์— ์˜ํ•ด ์‹คํ–‰ -> ์œ ์ €๋Š” HTML ์–ป์Œ ๊ทธ ๋‹ค์Œ, ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ hydrate -> ์ƒํ˜ธ์ž‘์šฉ ๊ฐ€๋Šฅ ๋ชจ๋“  ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ์ถ”๊ฐ€, useState, API, ์ง€๋ฆฌ ์ •๋ณด..etc ์›ํ•˜๋Š” ๊ฒฝ์šฐ ํด๋ผ์ด์–ธํŠธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ ๋‚ด์— ํฌํ•จ ๊ฐ€๋Šฅ (๋ฐ˜๋Œ€์˜ ๊ฒฝ์šฐ X) "use client"๋ฅผ ์“ฐ์ง€ ์•Š์œผ๋ฉด, ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ชจ๋‘ ์„œ๋ฒ„ ์ปดํฌ๋„ŒํŠธ์ด๋‹ค.

Next.js 2024.03.19

[Next.js] Library vs Framework

Library (ex. React) ์ฝ”๋“œ ๋‚ด์—์„œ ์œ ์ €์˜ ํ•„์š”์— ์˜ํ•ด ์ด์šฉ, ํ™œ์šฉํ•˜๋Š” ๊ฒƒ ex. ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ..etc => ๊ตฌ์กฐ์— ๊ด€ํ•œ ๋ชจ๋“  ๊ฒฐ์ •์€ ์œ ์ €๊ฐ€ ๋‚ด๋ฆฐ๋‹ค. React : UI ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ build ํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ Framework (ex. Next.js) ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ ๋‚˜์˜ ์ฝ”๋“œ๋ฅผ ํ™œ์šฉํ•œ๋‹ค => ์œ ์ €์˜ ์ฃผ๋„๊ถŒ X ์—ฌ๋Ÿฌ ๊ฒฐ์ •์„ ์œ ์ € ๋Œ€์‹ ํ•ด์ฃผ๊ณ , ์ž๋™ํ™” ์‹œํ‚จ๋‹ค ์œ ์ €๊ฐ€ ํ”„๋ ˆ์ž„์›Œํฌ์˜ ๊ทœ์น™์„ ์ง€์ผœ์•ผํ•œ๋‹ค.

Next.js 2024.03.15

[Next.js] CSR(client side render) vs SSR(server side render)

* Rendering : js code๋ฅผ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” html๋กœ ๋ฐ”๊พธ๋Š” ๊ฒƒ - React render : CSR (client side rendering) create-react-app ์„ ์‚ฌ์šฉํ•ด react๋งŒ์œผ๋กœ application์„ ์ƒ์„ฑํ•˜๋ฉด , client side rendering client side rendering => ์‚ฌ์šฉ์ž ๋ธŒ๋ผ์šฐ์ €์ธ client๋‹จ์—์„œ rendering ์ž‘์—…์„ ํ•œ๋‹ค. ๋‹จ์  ํŽ˜์ด์ง€์˜ ์‹ค์ œ ์†Œ์Šค์ฝ”๋“œ๋Š” ๋น„์–ด์žˆ๋‹ค. ex. = UI๊ฐ€ ์—†๋‹ค ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ๋ชจ๋“  JS ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ , ์‹คํ–‰ํ•œ ํ›„์—์•ผ ํ™”๋ฉด์— ๋ณด์—ฌ์ง€๋Š” ๊ฒƒ ์ƒˆ๋กœ๊ณ ์นจ ์‹œ, JS์—”์ง„์ด ์œ„์˜ ์‚ฌํ•ญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์‹œ๊ฐ„ ๋™์•ˆ ๋นˆ ํ™”๋ฉด์ด ๋ณด์—ฌ์ง SEO, ๊ฒ€์ƒ‰ ์—”์ง„ ์ตœ์ ํ™” Search Engine Optimization Goo..

Next.js 2024.03.15

[Next.js] Next ํ”„๋กœ์ ํŠธ ์ˆ˜๋™ setup

1. ํ”„๋กœ์ ํŠธ ํด๋” ๋งŒ๋“ค๊ธฐ $ mkdir prj_folder 2. ํ”„๋กœ์ ํŠธ ํด๋”๋กœ ์ด๋™ $ cd prj_folder 3. ํ•ด๋‹น ํด๋”๋ฅผ VSCode์—์„œ ์—ด์–ด๋ณด๊ธฐ $ code . 4. package.json ํด๋” ์ƒ์„ฑ $ npm init -y 5. ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜ - react : UI์™€ ๋‹ค๋ฅธ ๋ชจ๋“  ๊ฒƒ์„ ๊ตฌ์„ฑ - react-dom : ์œ„์˜ ๊ฒƒ์„ ๋ธŒ๋ผ์šฐ์ €์˜ Document Object Model(DOM)์— ๋ Œ๋”ํ•˜๋Š” ์—ญํ•  $ npm install react@latest next@latest react-dom@latest 6. jackage.json ์Šคํฌ๋ฆฝํŠธ ์ˆ˜์ • "scripts" : { "dev" : "next dev" }, 7. ํ”„๋กœ์ ํŠธ ์‹คํ–‰ ํ™•์ธ $ npm run dev - local server ์‹ค..

Next.js 2024.03.14