React 8

๋ธ”๋กœ๊ทธ ์ด์ „ ๊ด€๋ จ, ์ž๋ฃŒ ์กฐ์‚ฌ

Jekyll 2008 release Ruby๋กœ ์ž‘์„ฑ๋œ ์ •์  ์‚ฌ์ดํŠธ ์ƒ์„ฑ๊ธฐ(SSG, Static Site Generator) JavaScript๊ฐ€ ์‹คํ–‰๋˜๋ฉด ๋นˆ HTML ํŽ˜์ด์ง€ ์•ˆ์— ๋งˆํฌ์—…์„ ์ถ”๊ฐ€ํ•ด์ฃผ๋Š” SPA(Single Page Application)์™€ ๋‹ค๋ฅด๊ฒŒ, ๊ฐœ๋ฐœ ํ›„ Build ๊ณผ์ •์—์„œ ๋งˆํฌ์—… ์ƒ์„ฑ -> ๊ฒ€์ƒ‰ ์—”์ง„ ์ตœ์ ํ™”(SEO) Github Pages์—์„œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ง€์›ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ์˜ฌ๋ฆฌ๋ฉด ์ž๋™์œผ๋กœ ์›น ํŽ˜์ด์ง€ ํ˜ธ์ŠคํŒ… ํ…œํ”Œ๋ฆฟ ์—”์ง„๊ณผ ๋‚ด๋ถ€ ๋ฐ์ดํ„ฐ ์ฟผ๋ฆฌ๋Š” Liquid ์–ธ์–ด ์‚ฌ์šฉ Gatsby 2015 release JAM Stack(JavaScript, API, Markup) ์›น ๊ตฌ์„ฑ ๋ฐฉ๋ฒ• JAM Stack ๋™์ž‘ ์›๋ฆฌ ๊ธฐ์กด : ์„œ๋ฒ„์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋˜๋Š” CMS(Content Management S..

etc 2024.03.27

[React] Promise.all() , Suspense | ์—ฌ๋Ÿฌ ๋น„๋™๊ธฐ ํ•จ์ˆ˜ ์ตœ์ ํ™”

๊ธฐ์กด ์ฝ”๋“œ ๋น„๋™๊ธฐ์ ์œผ๋กœ getMovie ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋˜๊ณ  ์™„๋ฃŒ ํ›„, getVideo ํ•จ์ˆ˜ ์‹คํ–‰ => ๋ฐ์ดํ„ฐ ์–‘์ด ๋งŽ์„ ๊ฒฝ์šฐ ๋น„ํšจ์œจ์  async function getMovie(id: string) { const response = await fetch(`${API_URL}/${id}`); return response.json(); } async function getVideos(id: string) { const response = await fetch(`${API_URL}/${id}/videos`); return response.json(); } //dynamic route export default async function MovieDetail({ params: { id } }: { params: {..

React 2024.03.20

[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

[React] Vite + React + TS ๊ฐœ๋ฐœ ์„œ๋ฒ„ ๊ตฌ์ถ•

Node.js ์„ค์น˜ Node.js Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. nodejs.org Node.js ์„ค์น˜ ํ™•์ธ node -v Vite : ๊ฐœ๋ฐœํ™˜๊ฒฝ ๊ตฌ์„ฑ Vite Vite, ์ฐจ์„ธ๋Œ€ ํ”„๋ŸฐํŠธ์—”๋“œ ๊ฐœ๋ฐœ ํˆด ko.vitejs.dev npm create vite@latest - Projet name - framework : React - variat : TypeScript + SWC ( SWC: Rust typescript ์ปดํŒŒ์ผ๋Ÿฌ) ๊ธฐ๋ณธ์„ค์ • ์ฃผ์ž… npm i - react, react dom, typescript, vite...etc (package.json) ์ •์ƒ ์ž‘๋™ ํ™•์ธ npm run dev git ์—ฐ๊ฒฐ git ..

React 2024.02.26