React 3

[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

[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

[React] React Hooks

useState : React์˜ ๊ฐ€์žฅ ๊ธฐ๋ณธ์ด ๋˜๋Š” Hook์œผ๋กœ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ฆฌ๋ Œ๋”(re-render) ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค. setState๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ state์˜ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๋ฉด, ๋ณ€๊ฒฝ๋œ ๊ฐ’์„ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•ด ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ฆฌ๋ Œ๋”๋œ๋‹ค. - setState๋Š” ๋™๊ธฐ์ ์œผ๋กœ ๋™์ž‘ํ•œ๋‹ค. -> ์—ฐ์†์œผ๋กœ ์—ฌ๋Ÿฌ๋ฒˆ ์‹คํ–‰ํ•  ๊ฒฝ์šฐ, ์—…๋ฐ์ดํŠธ๋œ state๋ฅผ ๋ณด์žฅ๋ฐ›์ง€ ๋ชปํ•œ๋‹ค. - state๊ฐ€ ๋ณ€ํ•  ๊ฒฝ์šฐ, ์ปดํฌ๋„ŒํŠธ ์ „์ฒด๊ฐ€ ๋ฆฌ๋ Œ๋”๋œ๋‹ค. -> ์ปดํฌ๋„ŒํŠธ ๋‚ด๋ถ€์— ์ •์˜๋œ ๋ชจ๋“  ๋ณ€์ˆ˜์™€ ํ•จ์ˆ˜๊ฐ€ ์žฌ์„ ์–ธ, ์žฌ์‹คํ–‰๋œ๋‹ค. -> ์„ฑ๋Šฅ์ €ํ•˜ ์ด์Šˆ useEffect : ํ•จ์ˆ˜์™€ ๋ณ€์ˆ˜๋ฅผ ๋ฐ›์•„, ๋ณ€์ˆ˜์˜ ๊ฐ’์ด ๋ณ€๊ฒฝ๋  ์‹œ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰์‹œํ‚จ๋‹ค. ๋ณ€์ˆ˜๋Š” ์˜์กด์„ฑ ๋ฐฐ์—ด(dependency array)๋กœ ์—ฌ๋Ÿฌ ๊ฐ’์„ ํฌํ•จ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค. ์˜์กด์„ฑ ๋ฐฐ์—ด์ด ๋น„์–ด์žˆ์„ ๊ฒฝ์šฐ, ์ตœ์ดˆ ๋ Œ๋”๋ง ์‹œ ํ•œ๋ฒˆ๋งŒ ..

React 2023.09.15