๋ฐ˜์‘ํ˜•

๋ฆฌ์•กํŠธ ์Šคํ„ฐ๋”” 2

[React] Zustand ์„ค์น˜ ๋ฐฉ๋ฒ• ๋ฐ ์˜ˆ์ œ ์‚ดํŽด๋ณด๊ธฐ

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” Zustand ์„ค์น˜ ๋ฐฉ๋ฒ• ๋ฐ ์˜ˆ์ก”๋ฅผ ์‚ดํŽด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ทธ์ „์— ์•ž์„œ zustand ๊ฐ€ ๋ฌด์—‡์ธ์ง€ ๊ถ๊ธˆํ•˜์‹  ๋ถ„๋“ค์€ ์œ„ ํฌ์ŠคํŒ… ์ฐธ๊ณ  ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค :) How to install Zustand Zustand ์„ค์น˜๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฐ์ž ์‚ฌ์šฉํ•˜๋Š” ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ ํˆด(npm / yarn)์— ๋งž์ถฐ ์„ค์น˜ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. 1. npm npm install zustand 2. yarn yarn add zustand Zustand Simple Example ๊ฐ„๋‹จํ•œ ์˜ˆ์ œ๋กœ ์นด์šดํ„ฐ๋ฅผ ๋งŒ๋“ค์–ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. zustand๋ฅผ importํ•˜๊ณ , ์ƒํƒœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•ด์ค๋‹ˆ๋‹ค. ์ปจํ…Œ์ด๋„ˆ ์•ˆ์—๋Š” count, increment(), decrement()์ด ๋“ค์–ด์žˆ์Šต๋‹ˆ๋‹ค. import create fro..

Framework/React 2023.04.17

[React] ๋กœ๋”ฉ๋ฐ”(loading bar) ํ‘œ์‹œ ๋ฐ ๋กœ๋”ฉ ์†๋„ ์กฐ์ ˆํ•˜๋Š” ๋ฐฉ๋ฒ• (+ setTimeout)

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ๋ฆฌ์•กํŠธ์—์„œ ๋กœ๋”ฉ๋ฐ” ํ‘œ์‹œ ๋ฐ ๋กœ๋”ฉ ์†๋„๋ฅผ ์กฐ์ ˆํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. How to solve the problem ๋‹ค์Œ์˜ List ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ด…์‹œ๋‹ค. handleFilterClickํ•จ์ˆ˜๋ฅผ ํด๋ฆญ ํ• ๋•Œ๋งˆ๋‹ค ํ•„ํ„ฐ๊ธฐ๋Šฅ์ด ์ž‘๋™๋˜๋Š” ๋กœ์ง์ž…๋‹ˆ๋‹ค. ํ•„ํ„ฐ๋ฅผ ๋ˆ„๋ฅผ ๋•Œ๋งˆ๋‹ค ํ•„ํ„ฐ๊ฐ€ ๋œ๋“ฏํ•œ ๋™์ž‘์„ ํ‘œํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ๋กœ๋”ฉ๋ฐ”๋ฅผ ์ถ”๊ฐ€๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. const List: NextPage = () => { const {dataList, setDataList} = useLoginStore(); const [totalCtn, setTotalCtn] = useState(); const [filterStatus, setFilterStatus] = useState("ALL"); const..

Framework/React 2023.04.05
๋ฐ˜์‘ํ˜•