The journey to becoming a developer

My future is created by what I do today, not tomorrow.

What I learned/CodeSquad Log

CodeSquad Day 84 : Project 3 - Day 4

Millie 2022. 5. 13. 11:52

CodeSquad๐Ÿ”นDay 84

Vending Machine Project

Design

Figma ์‹œ์•ˆ
์žํŒ๊ธฐ UI ์™„์„ฑ

grid๋ฅผ ์ ์šฉํ•ด์„œ ์žํŒ๊ธฐ ๋””์ž์ธ์„ ๊ฑฐ์˜ ์™„๋ฃŒํ–ˆ๋‹ค. ๋„์•ˆ๊ณผ ๋น„๊ตํ•ด ๋ณด๋‹ˆ, ์•ฝ๊ฐ„ ๋‹ค๋ฅธ ์ ๋„ ์žˆ์ง€๋งŒ ๊ฑฐ์˜ ๋น„์Šทํ•˜๊ฒŒ ๋‚˜์™”๋‹ค. 

 

React Router v6 ์ ์šฉ

 

React Router v6 ํŠœํ† ๋ฆฌ์–ผ

๋ฆฌ์•กํŠธ ๋ผ์šฐํ„ฐ v6๋ฅผ ์ƒˆ๋กœ ์ ‘ํ•˜์‹œ๋Š” ๋ถ„๋“ค์„ ์œ„ํ•œ ํŠœํ† ๋ฆฌ์–ผ์„ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ฆฌ์•กํŠธ ๋ผ์šฐํ„ฐ v6 ์˜ ๊ธฐ๋ณธ์ ์ธ ์‚ฌ์šฉ๋ฒ•, ๊ทธ๋ฆฌ๊ณ  ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ์ œ๊ณตํ•˜๋Š” ๋‹ค์–‘ํ•œ ์œ ์šฉํ•œ ๊ธฐ๋Šฅ๋“ค์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ด…์‹œ

velog.io

์œ„ ๊ธ€์„ ์ฐธ๊ณ ํ•ด์„œ React Router๋ฅผ ํ•™์Šตํ•˜๊ณ  ์ ์šฉํ•ด ๋ณด์•˜๋‹ค. ๊ฐœ๋…๋ถ€ํ„ฐ ์ฝ”๋“œ ์˜ˆ์ œ๊นŒ์ง€ ์ฐจ๊ทผ์ฐจ๊ทผ ์“ฐ์—ฌ ์žˆ์–ด์„œ ๊ณต๋ถ€ํ•˜๊ธฐ ๋งค์šฐ ์ข‹์•˜๋‹ค. 

์ค‘์ฒฉ๋œ Route๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, Outlet ์ปดํฌ๋„ŒํŠธ๋ฅผ ์จ์„œ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ์‹ ๊ธฐํ•˜๋ฉด์„œ๋„ ํŽธํ–ˆ๋‹ค. Outlet์€ Route์˜ children์œผ๋กœ ๋“ค์–ด๊ฐ€๋Š” JSX ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ๋ณด์—ฌ ์ค€๋‹ค.

๋นจ๊ฐ„ ์ƒ‰์œผ๋กœ ํ‘œ์‹œํ•œ Route์˜ children์€ Vendor, Wallet, Stock, NotFound๊ฐ€ ์žˆ๋‹ค. 

components ํด๋”์— Layout.jsx๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค๊ณ  Navbar๋ฅผ ์ตœ์ƒ๋‹จ์— ๋„ฃ๊ณ , InnerContainer ์•ˆ์— Outlet ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋„ฃ์–ด์ฃผ์—ˆ๋‹ค. ์ด Outlet์˜ ์ž๋ฆฌ์— Route์˜ children์ธ Vendor, Wallet, Stock, NotFound ๊ฐ€ ๋“ค์–ด์˜ค๊ฒŒ ๋œ๋‹ค. 

 

NavLink

Link ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ ์šฉํ•ด๋„ ๋˜์ง€๋งŒ ์ข€ ๋” ๋ถ€๊ฐ€์ ์ธ ๊ธฐ๋Šฅ์ด ํฌํ•จ๋œ ์ปดํฌ๋„ŒํŠธ์ธ NavLink ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ฒ˜์Œ ์ ์šฉํ•ด ๋ณด์•˜๋‹ค. ๋”ฑ Navigation Bar๋ฅผ ์œ„ํ•œ ์ปดํฌ๋„ŒํŠธ๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ๋‹ค. 

NavLink ์ปดํฌ๋„ŒํŠธ๋Š” ๋งํฌ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ๋กœ๊ฐ€ ํ˜„์žฌ ๋ผ์šฐํŠธ์˜ ๊ฒฝ๋กœ์™€ ์ผ์น˜ํ•˜๋Š” ๊ฒฝ์šฐ, ํŠน์ • ์Šคํƒ€์ผ ํ˜น์€ CSS class๋ฅผ ์ ์šฉํ•ด์ค€๋‹ค. style์ด๋‚˜ className์„ ์„ค์ •ํ•  ๋•Œ { isActive: boolean } ์„ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์ „๋‹ฌ๋ฐ›๋Š” ํ•จ์ˆ˜ ํƒ€์ž…์˜ ๊ฐ’์„ ์ „๋‹ฌํ•œ๋‹ค. 

๋‚˜๋Š” ์ด๋ ‡๊ฒŒ NavLink๋ฅผ ์ ์šฉํ•ด๋ดค๋‹ค. style ์•ˆ์— ๊ฐ™์€ ํ•จ์ˆ˜๊ฐ€ ๋“ค์–ด๊ฐ€๊ฒŒ ๋˜๋Š”๋ฐ ์ด๊ฒƒ๋„ ์ค‘๋ณต ์ œ๊ฑฐ๋ฅผ ํ•  ์ˆ˜ ์žˆ์„๊นŒ? 

 

Not Found page

wildcard ๋ฌธ์ž์ธ *๋ฅผ ์‚ฌ์šฉํ•ด์„œ Not Found ํŽ˜์ด์ง€๋„ ๋งŒ๋“ค์–ด ๋ณด์•˜๋‹ค. ์ด๊ฒƒ์€ ์•„๋ฌด ํ…์ŠคํŠธ๋‚˜ ๋งค์นญ์„ ํ•œ๋‹ค๋Š” ๊ฑด๋ฐ ์šฐ์„  ํ•ด๋‹น Route Element์˜ ์ƒ๋‹จ์— ์žˆ๋Š” Route๋“ค์˜ ๊ทœ์น™์„ ๋ชจ๋‘ ํ™•์ธํ•œ ํ›„์— ์ผ์น˜ํ•˜๋Š” Route๊ฐ€ ์—†์œผ๋ฉด Not Found ํ™”๋ฉด์ด ๋‚˜ํƒ€๋‚˜๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. 

 

๐Ÿ˜ฑ ํฐํŠธ ์ ์šฉ

์‚ฌ์‹ค ํฐํŠธ๋ฅผ ์ ์šฉํ•  ๋•Œ ๋งŽ์ด ๊ณ ์ƒํ–ˆ๋‹ค. GlobalStyle์— ์•„๋ฌด๋ฆฌ ์ ์šฉ์„ ์ œ๋Œ€๋กœ ํ–ˆ์–ด๋„ ์ œ๋Œ€๋กœ ์ ์šฉ์ด ์•ˆ ๋˜์—ˆ๋‹ค. ์ด๊ฑธ๋กœ ๊ฑฐ์˜ 1์‹œ๊ฐ„ ๋„˜๊ฒŒ ๋ณด๋‚ด๋‹ค๊ฐ€, ํ–„๋””๊ฐ€ Zoom ๋ชจ๊ฐ์ฝ” ๋ฐฉ์„ ์—ด์—ˆ๊ธธ๋ž˜ ์ฐธ๊ฐ€ํ–ˆ๋‹ค. ๊ฑฐ๊ธฐ์„œ ํฐํŠธ ์ ์šฉํ•˜์‹  ๋ถ„์ด ์žˆ๋Š”์ง€ ์งˆ๋ฌธํ–ˆ๋Š”๋ฐ ์ฝœ๋ผ๊ฐ€ ์ ์šฉํ–ˆ๋‹ค๊ณ  ํ•ด์„œ ๊ฒŒ๋”ํƒ€์šด์—์„œ ํ•จ๊ป˜ ์›์ธ์„ ์ฐพ์•„๊ฐ€๋ดค๋‹ค.

reset css๋„ ์ œ๊ฑฐํ•ด๋ณด๊ณ , ๊ฐœ๋ฐœ์ž ๋„๊ตฌ Network ํƒญ๋„ ์‚ดํŽด๋ณด๊ณ  ๋‹ค์–‘ํ•œ ์‹œ๋„๋ฅผ ํ–ˆ์ง€๋งŒ ๊ฒฐ๊ตญ ์›์ธ์„ ์ฐพ์ง€ ๋ชปํ–ˆ๋‹ค.

GlobalStyle์— ์ ์šฉํ•˜๋ฉด ์•ˆ ๋˜๊ณ  index.css์— ์ ์šฉํ•˜๋‹ˆ๊นŒ ๋œ๋‹ค.

GlobalStyle ๋‚ด๋ถ€์—์„œ @import url๋กœ ํ•˜๋ฉด ์•ˆ ๋˜์—ˆ๊ณ , index.css์— ์ ์šฉํ•˜๋‹ˆ ๋˜์—ˆ๋‹ค. Font ํ•˜๋‚˜ ๋•Œ๋ฌธ์— index.css๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒŒ ์˜ ๋งˆ๋•…์น˜ ์•Š์•˜์ง€๋งŒ ์ง€๊ธˆ์œผ๋กœ์จ๋Š” ํฐํŠธ๋ฅผ ์ ์šฉํ•˜๋ ค๋ฉด ์ด ๋ฐฉ๋ฒ•๋ฐ–์— ์—†์–ด์„œ ์ด๋ ‡๊ฒŒ ํ•ด์•ผ ํ–ˆ๋‹ค.  

๊ทธ๋Ÿฐ๋ฐ ์ด์ƒํ•œ ์ ์€ ์ฝœ๋ผ๋Š” GlobalStyle์— ํ–ˆ๋Š”๋ฐ๋„ ์ž˜ ๋˜์—ˆ๋˜ ๊ฒƒ์ด๋‹ค. ํ˜น์‹œ ์˜คํƒ€ ๋ฌธ์ œ์ผ๊นŒ ํ–ˆ๋Š”๋ฐ ๊ทธ๊ฑด ์•„๋‹ˆ์—ˆ๋‹ค. 

์ฝœ๋ผ์™€ ์›์ธ์„ ์ฐพ์•„๊ฐ€๋ฉด์„œ ๋ฌธ์ œ์˜ ์›์ธ์„ ํŒŒ์•…ํ•ด ๋‚˜๊ฐ€๋Š” ์ž์„ธ๋ฅผ ๋งŽ์ด ๋ฐฐ์› ๋‹ค. ํฌ๊ธฐํ•˜์ง€ ์•Š๊ณ  ๋‹ค๋ฐฉ๋ฉด์œผ๋กœ ์ฐพ์•„๋ณด๋ฉฐ ์ ๊ทน์ ์œผ๋กœ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋ ค๋Š” ํƒœ๋„๊ฐ€ ๋งค์šฐ ์ข‹๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค. ์ด๊ฒƒ ๋ง๊ณ ๋„ ์ฝœ๋ผ์™€ ์ƒˆ๋ฒฝ 2์‹œ๊นŒ์ง€ ๊ฐœ๋ฐœ ๊ด€๋ จ ์ˆ˜๋‹ค๋ฅผ ๋งŽ์ด ํ–ˆ๋Š”๋ฐ ์ง€์ ์ธ ์ž๊ทน์„ ๋งŽ์ด ๋ฐ›์„ ์ˆ˜ ์žˆ์—ˆ๋‹ค. 

 


์š”์ฆ˜ ๋“ค์–ด ์ปดํ“จํ„ฐ๋ฅผ ๊ฐ•์ œ์ข…๋ฃŒํ•˜๋Š” ์ผ์ด ์žฆ์•„์กŒ๋‹ค. VS Code, Zoom, Gather town, Figma ๋“ฑ๋“ฑ ์—ฌ๋Ÿฌ ๊ฐ€์ง€๋ฅผ ํ•œ๊บผ๋ฒˆ์— ๋„์›Œ๋†“์œผ๋ฉด ๋…ธํŠธ๋ถ์ด ๋ฒ„๊ฑฐ์›Œํ•œ๋‹ค. ํฌ๋งท์„ ํ•œ ๋ฒˆ ํ•˜๋ฉด ๋” ๋‚˜์•„์งˆ๊นŒ? ๊ณ ๋ฏผ์ด ๋œ๋‹ค. 

 

'What I learned > CodeSquad Log' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

CodeSquad Day 86 : Project 3 - Day 6  (0) 2022.05.17
CodeSquad Day 85 : Project 3 - Day 5  (0) 2022.05.15
CodeSquad Day 83 : Project 3 - Day 3  (0) 2022.05.12
CodeSquad Day 82 : Project 3 - Day 2  (0) 2022.05.11
CodeSquad Day 81 : Project 3 - Day 1  (0) 2022.05.10