React

ยท React
์ด์ „๋ถ€ํ„ฐ Webpack์„ ์ด์šฉํ•ด ๋งŒ๋“ค์–ด๋‘๊ณ  ์‹ถ์—ˆ๋˜ React ๋ณด์ผ๋Ÿฌํ”Œ๋ ˆ์ดํŠธ๋ฅผ ๋งŒ๋“ค์–ด๋ดค๋‹ค. ์—ฌ๋Ÿฌ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ์ฐธ๊ณ ํ•˜๋ฉฐ ๋งŒ๋“ค์–ด๋ดค๋Š”๋ฐ ํ”Œ๋Ÿฌ๊ทธ์ธ ๋ถ€ํ„ฐ ๋กœ๋”, ์„ค์ • ๋‚ด์šฉ๊นŒ์ง€ ํ•˜๋‚˜ํ•˜๋‚˜ ์ฐจ๊ทผ์ฐจ๊ทผ ๊ธฐ๋กํ•˜๋ฉฐ ์‚ดํŽด๋ณด์ž. ํšŒ์‚ฌ์— ๋‚ด๊ฐ€๋งŒ๋“  ๋ณด์ผ๋Ÿฌํ”Œ๋ ˆ์ดํŠธ, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋“ฑ๋“ฑ์ด ์ ์  ์Œ“์—ฌ๊ฐ€๋Š” ๊ฑธ ๋ณด๋ฉฐ ํž˜๋“ค์ง€๋งŒ ๋ฟŒ๋“ฏํ•œ ์š”์ฆ˜์ด๋‹ค..โญ๏ธ Webpack ์ด๋ž€? ์›นํŒฉ์€ ๋‹จ์ˆœํžˆ ๋งํ•˜์ž๋ฉด ๋ชจ๋“ˆ ๋ฒˆ๋“ค๋Ÿฌ์ด๋‹ค. ๋ชจ๋“ˆ : ์›นํŒฉ์—์„œ์˜ ๋ชจ๋“ˆ์€ ๊ฐ์ข… .js .css .png ๋“ฑ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ตฌ์„ฑํ•˜๋Š” ์ž์›์„ ๋งํ•œ๋‹ค. ๋ฒˆ๋“ค๋Ÿฌ : ์ž์›์„ ์กฐํ•ฉํ•ด์„œ ๋นŒ๋“œ ๊ฒฐ๊ณผ๋ฌผ์„ ๋งŒ๋“œ๋Š” ์—ญํ•  ES2015๋ถ€ํ„ฐ ๋ชจ๋“ˆ ์ด๋ผ๋Š” ๋ฌธ๋ฒ•์„ ์ง€์›ํ•˜๊ฒŒ ๋˜์—ˆ๊ณ  ์ด ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ์ฝ”๋“œ๋‚˜ ๋‚ด๊ฐ€ ๋งŒ๋“  ์ฝ”๋“œ๋“ค์„ ์žฌ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค. ๊ธฐ์กด์—๋Š” ํƒœ๊ทธ๋ฅผ ํ†ตํ•ด ์ฝ”๋“œ๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๊ณ  ..
ยท React
์š”์ฆ˜ Next.js๋ฅผ ์‚ฌ์šฉํ•˜๋ฉฐ CSS-IN-JS ๋Œ€์‘์ด ์•ˆ๋˜๋Š” ๋ฌธ์ œ๋กœ Tailwind CSS๋ฅผ ์ž์ฃผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค. VScode ์—์„œ Tailwind CSS IntelliSense ๋ผ๋Š” ํ™•์žฅ ํ”„๋กœ๊ทธ๋žจ์„ ์ œ๊ณตํ•ด Tailwind์—์„œ ์ •ํ•ด์ง„ ํฌ๋งท์„ ๋ณด์—ฌ์ฃผ์ง€๋งŒ ์•ฝ๊ฐ„์˜ ๋ถˆํŽธํ•จ์ด ์žˆ๋‹ค. ์„ค์ •์„ ํ†ตํ•ด ํ•ด๊ฒฐํ•ด๋ณด์ž! Tailwind Tailwind๋Š” CSS ํ”„๋ ˆ์ž„์›Œํฌ๋กœ ์—„์ฒญ๋‚˜๊ฒŒ ๋งŽ์€ utility class๋กœ ์ด๋ฃจ์–ด์ง„ ํ”„๋ ˆ์ž„์›Œํฌ๋‹ค. ๋งŒ๋“ค์–ด์ ธ ์žˆ๋Š” utility class๋ฅผ class์— ๋„ฃ์–ด์ฃผ๊ธฐ๋งŒ ํ•˜๋ฉด ํ•ด๋‹น ์Šคํƒ€์ผ๋ง์ด ์ ์šฉ๋œ๋‹ค. ์‚ฌ์šฉ๋ฒ• ์„ค์น˜๋ฐฉ๋ฒ•์€ ๊ณต์‹ํŽ˜์ด์ง€๋ฅผ ์ฐธ๊ณ ํ•˜์ž. ๊ณต์‹ํŽ˜์ด์ง€๋ฅผ ๋”ฐ๋ผ ์„ค์น˜ํ–ˆ๋‹ค๋ฉด ์‚ฌ์šฉ๋ฒ•์€ ๋ณ„๊ฑฐ ์—†๋‹ค. function App() { return ( ); } export default App; ์ •ํ•ด์ง„ uti..
ยท React
ํšŒ์‚ฌ์—์„œ 4deps์˜ ์นดํ…Œ๊ณ ๋ฆฌ ๊ธฐ๋Šฅ์„ ๋งŒ๋“ค์–ด์•ผ ํ–ˆ๋Š”๋ฐ ์žฌ๊ท€ ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ™œ์šฉํ•ด ๋ฐ˜๋ณต ์ฝ”๋“œ๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. 4deps๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์žก์•˜์ง€๋งŒ ์žฌ๊ท€๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ช‡ deps๋“  ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ์ฃ ! ์„ฑ๋Šฅ์ ์ธ ๋ฌธ์ œ๋Š” ๋ณ„๊ฐœ์ง€๋งŒ ๋ธŒ๋ผ์šฐ์ €์˜ ์„ฑ๋Šฅ์ด ๋ฐœ๋‹ฌํ•˜๋ฉด์„œ ์ด์ •๋„๋Š” ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค ํŒ๋‹จํ–ˆ์Šต๋‹ˆ๋‹ค. ์žฌ๊ท€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์žฌ๊ท€๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ํ•˜๋‚˜๋กœ ์ฃผ๋กœ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ๋ฌธ์ œ๋ฅผ ํ’€ ๋•Œ ๋งŽ์ด ์ ‘ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ๊ฐ€์žฅ ๋Œ€ํ‘œ์ ์ธ ์žฌ๊ท€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•œ ์‚ฌ๋ก€๋กœ๋Š” ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜์—ด์ด ์žˆ๋‹ค. const fibonacci = (num: number) => { if (num < 2) { return num; } return fibonacci(num - 1) + fibonacci(num - 2); }; ๊ฐ„๋‹จํ•˜๊ฒŒ ์„ค๋ช…ํ•˜์ž๋ฉด "์ž๊ธฐ ์ž์‹ ์„ ํ˜ธ์ถœํ•˜๋Š” ํ•จ์ˆ˜"๋ฅผ ์žฌ๊ท€ ํ•จ์ˆ˜..
ยท React
debnounce๋ž€ ? - debounce๋Š” ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ˆœ์ฐจ์  ์ด๋ฒคํŠธ ํ˜ธ์ถœ์„ ๋งˆ์ง€๋ง‰(๋˜๋Š” ์ฒ˜์Œ) ํ•˜๋‚˜์˜ ํ˜ธ์ถœ๋งŒ ํ•˜๋„๋ก ํ•˜๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ๋ฒ• - ์ฃผ๋กœ ๊ฒ€์ƒ‰, ์Šคํฌ๋กค ๊ฐ™์€ ๋ฐ˜๋ณต์ ์ธ ์ด๋ฒคํŠธ๊ฐ€ ์ผ์–ด๋‚  ๋•Œ ์‚ฌ์šฉํ•˜๋ฉฐ ์œ ๋ช…ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ธ lodash๋ฅผ ์„ค์น˜ํ•˜๋ฉด ๊ฐ„๋‹จํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. - ๋งŒ์•ฝ ํšŒ์›๊ฐ€์ž…์—์„œ ์ด๋ฉ”์ผ์˜ ์ค‘๋ณตํ™•์ธ์„ onChange ์ด๋ฒคํŠธ๋กœ ์ฒดํฌํ•œ๋‹ค๊ณ  ํ–ˆ์„ ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ๋งˆ๋‹ค API ํ˜ธ์ถœ์„ ํ•˜๊ฒŒ ๋˜๋Š”๋ฐ ์ด๋Ÿฌ๋ฉด ๋”์งํ•œ ์„œ๋ฒ„ ๋น„์šฉํญํƒ„์„ ๋งž์„ ์ˆ˜ ์žˆ๋‹ค. debouncing ์˜ˆ์ œ useEffect(() => { console.log(`http ์š”์ฒญ ${formData.email}`); }, [formData.email]); useEffect๋ฅผ ์ด์šฉํ•ด email input์ด ์„œ๋ฒ„์— ๊ฐ™์€ ์•„์ด๋””๊ฐ€ ์žˆ๋Š”์ง€ ์ค‘๋ณตํ™•์ธ..
ยท React
useState โญ๏ธ React์˜ state๋Š” ์ปดํฌ๋„ŒํŠธ ๋‚ด๋ถ€์˜ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ ํ•œ ๊ฐ’์ด๋‹ค. ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์—์„œ useState ํ›…์„ ์‚ฌ์šฉํ•ด ์ƒํƒœ๋ฅผ ๋ณ€๊ฒฝํ•œ๋‹ค. import React, { useState } from 'react'; function App() { const [number, setNumber] = useState(0); return ( {number} ); } export default App; React ํŒจํ‚ค์ง€์—์„œ useState๋ฅผ ๋ถˆ๋Ÿฌ์™€ import ํ›„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. useState์˜ ์ธ์ž์—๋Š” ์ดˆ๊ธฐ๊ฐ’์„ ํ• ๋‹นํ•œ๋‹ค. (๋ถˆ๋ฆฌ์–ธ์ด๋‚˜ ๋ฐฐ์—ด, ๊ฐ์ฒด๋„ ํ• ๋‹น ๊ฐ€๋Šฅ) useState๋Š” ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•˜๋Š”๋ฐ ์ด๋•Œ ์ฒซ๋ฒˆ์งธ number๋Š” ์›์†Œ์˜ ํ˜„์žฌ ์ƒํƒœ, ๋‘๋ฒˆ์งธ ์›์†Œ๋Š” Setterํ•จ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. setState..
ยท React
useLocation ํ›… โญ๏ธ useLocation ํ›…์€ ํ˜„์žฌ์˜ URL์„ ๋Œ€ํ‘œํ•˜๋Š” location '๊ฐ์ฒด' ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๊ฐ์ฒด์•ˆ์—๋Š” pathname, search, hash, state, key ํ”„๋กœํผํ‹ฐ๊ฐ€ ์กด์žฌํ•œ๋‹ค. pathname : ํ˜„์žฌ ์ฃผ์†Œ์˜ ๊ฒฝ๋กœ (์ฟผ๋ฆฌ์ŠคํŠธ๋ง, ํ•ด์‹œ ์ œ์™ธ) search : pathname ์ดํ›„์— ? ๋ถ€ํ„ฐ์˜ ๋ฌธ์ž์—ด (์ฟผ๋ฆฌ์ŠคํŠธ๋ง) hash : pathname ์ดํ›„์— # ๋ถ€ํ„ฐ์˜ ๋ฌธ์ž์—ด (ํ•ด์‹œ) state : location ๊ฐ์ฒด๋กœ ํ™”๋ฉด์ด๋™์„ ์‹œํ‚ฌ ๋•Œ ์ฝ”๋“œ ์ƒ์œผ๋กœ ๋ณด๋‚ด๋Š” ๊ฐ์ฒด key : history stack์—์„œ location ๊ฐ์ฒด๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•œ ๊ณ ์œ  ํ‚ค ์‚ฌ์šฉ๋ฒ• import { useLocation } from 'react-router-dom' const Home = () => { co..
ยท React
import { useState } from "react"; const useForm = (initialState = {}) => { const [formData, setFormData] = useState(initialState); const InputChangeHandler = (e) => { const { name, value } = e.target; setFormData({ ...formData, [name]: value }); }; return { formData, InputChangeHandler, }; }; export default useForm; Custom Hook์„ ์ด์šฉํ•ด form์„ ๋งŒ๋“ค๋•Œ ์žฌํ™œ์šฉ์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋งŒ๋“ค์–ด๋ดค๋‹ค. ์šฐ์„  initaialState์˜ Default ๊ฐ’์„ ๋นˆ ๊ฐ์ฒด๋กœ ๋งŒ..
ยท React
๋ฉ”๋ชจ์ด์ œ์ด์…˜(memoization) ์ด๋ž€?โญ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ ๋ฐ˜๋ณต๋˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅ ํ•ด๋†“๊ณ  ๋‹ค์Œ์— ๊ฐ™์€ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ฌ ๋•Œ ๋‹ค์‹œ ๊ณ„์‚ฐํ•  ํ•„์š”์—†์ด ๋นจ๋ฆฌ ์‹คํ–‰ ํ•˜๋Š” ๊ธฐ๋ฒ•์ด๋‹ค. JavaScript์—์„œ๋Š” ํด๋กœ์ € ๋ฅผ ํ†ตํ•ด ๊ณ„์† ์œ ์ง€๋˜๋Š” ์ €์žฅ๊ณต๊ฐ„์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ๋‘ hooks ๋Š” ๋ฉ”๋ชจ์ด์ œ์ด์…˜์„ ์ด์šฉํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ๋ถˆํ•„์š”ํ•œ ๋ Œ๋”๋ง์„ ๋ง‰์„ ์ˆ˜ ์žˆ์œผ๋‚˜, ์‚ฌ์šฉ ์ž์ฒด๋กœ๋„ ํ”„๋กœ๊ทธ๋žจ์— ์‚ฌ์šฉ๋Ÿ‰์ด ์ฑ„์›Œ์ง€๋ฏ€๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์ „ ์‹ ์ค‘ํžˆ ์ƒ๊ฐ ํ•ด ๋ด์•ผํ•œ๋‹ค. useMemo ์‚ฌ์šฉ๋ฒ• ๐Ÿ“„ const memo = useMemo(() => { return blabla; },[list]) useMemo๋Š” ์ฒซ๋ฒˆ์งธ ์ธ์ž๋กœ ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ๋‘๋ฒˆ์งธ ์ธ์ž๋กœ ์˜์กด์„ฑ(dependency) ๋ฐฐ์—ด์„ ๋ฐ›๋Š”๋‹ค. useMemo๋Š” list๊ฐ€ ๋ณ€ํ•œ๋‹ค๋ฉด ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜๊ณ  blab..
YunCow
'React' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก