The journey to becoming a developer

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

What I learned/CodeSquad Log

CodeSquad Day 72 : Team Project 2

Millie 2022. 4. 19. 21:54

 

CodeSquad๐Ÿ”นDay 72

Team Project 2์ผ์ฐจ - Create React App & Styled Components

์˜ค๋Š˜์€ ์ฝ”๋“œ์Šค์ฟผ๋“œ ์„ผํ„ฐ๋ฅผ 2022๋…„ ๋“ค์–ด์„œ ์ฒ˜์Œ์œผ๋กœ ๊ฐœ๋ฐฉํ•˜๋Š” ๋‚ ์ด์—ˆ๋‹ค. ํ™”๋ฉด์œผ๋กœ๋งŒ ์ ‘ํ–ˆ๋˜ ์ฝ”์ฟผ ๋ฉค๋ฒ„๋“ค ๊ทธ๋ฆฌ๊ณ  ํฌ๋กฑ๊ณผ ํ˜ธ๋ˆ…์Šค, ๋งค๋‹ˆ์ €์ธ ํด๋กœ์ด๋ฅผ ์‹ค๋ฌผ๋กœ ๋ณด๋‹ˆ ์‹ ๊ธฐํ•˜๊ธฐ๋„ ํ–ˆ๊ณ  ๋ฐ˜๊ฐ€์› ๋‹ค. ๋น„๋Œ€๋ฉด์ด ์•„๋‹ˆ์—ˆ์„ ์‹œ์ ˆ์— ์ฝ”๋“œ์Šค์ฟผ๋“œ์˜€๋‹ค๋ฉด ์ด ๊ณต๊ฐ„์„ ์ž์ฃผ ์™”๊ฒ ์ง€?

์‹ค๋ฌผ๋กœ ์ฒ˜์Œ ๋งŒ๋‚˜๋ฉด ์–ด์ƒ‰ํ• ๊นŒ ๊ฑฑ์ •ํ–ˆ์ง€๋งŒ ๋‹ค๋“ค ๋ฐ˜๊ฐ‘๊ฒŒ ์ธ์‚ฌํ•˜๊ณ  ์ด์•ผ๊ธฐ๋ฅผ ๋‚˜๋ˆ„์—ˆ์–ด์„œ ๊ทธ๋Ÿฐ ๊ฑฑ์ •์€ ๊ธˆ์ƒˆ ์‚ฌ๋ผ์กŒ๋‹ค. ํ–„๋””๊ฐ€ ๊ฒŒ๋”ํƒ€์šด์— ์ ‘์†ํ•ด์„œ ์ œ์ด๋ฏธ, ๋„ํ†จ, ํฌํ‚ค์—๊ฒŒ ์นด๋ฉ”๋ผ๋ฅผ ์ผœ๊ณ  ์„ผํ„ฐ ํˆฌ์–ด๋„ ์‹œ์ผœ์ฃผ์—ˆ๋‹ค. 

์ด๋ ‡๊ฒŒ ์ฆ๊ฑฐ์šด ์‹œ๊ฐ„์„ ๋ณด๋‚ด๋‹ค๊ฐ€, 3์‹œ์ฏค๋ถ€ํ„ฐ๋Š” ๋ฐฑ์—”๋“œ์ธ ๋™๊ธฐ, ์ค€๊ณผ ํ•จ๊ป˜ ์ž๋ฆฌ์— ์•‰์•„์„œ ์Šคํฌ๋Ÿผ์„ ํ•˜๊ณ  ๊ฐœ๋ฐœ์„ ์ง„ํ–‰ํ•˜๊ธฐ ์‹œ์ž‘ํ–ˆ๋‹ค. ๋งค๋ฒˆ ์˜จ๋ผ์ธ์œผ๋กœ๋งŒ ํ•˜๋˜ ์Šคํฌ๋Ÿผ์ด์—ˆ๋Š”๋ฐ ์ด๋ ‡๊ฒŒ ์˜คํ”„๋ผ์ธ์—์„œ ์ƒ์ƒํ•˜๊ฒŒ ํ•˜๋‹ˆ ๋Š๋‚Œ์ด ์ƒ‰๋‹ฌ๋ž๋‹ค.

์Šคํฌ๋Ÿผ ํ›„์—๋Š” ๋ณธ๊ฒฉ์ ์œผ๋กœ ํ”„๋กœ์ ํŠธ ์…‹์—…์— ๋Œ์ž…ํ–ˆ๋‹ค. ํ–„๋””์™€ ํ•จ๊ป˜ ์ž‘์„ฑํ–ˆ๋˜ ํ”„๋กœ์ ํŠธ ๋ชฉ๋ก๋“ค์„ ์–ด์ ฏ๋ฐค์— ๋‚ด๊ฐ€ ์ด์Šˆ๋กœ ์˜ฎ๊ฒจ๋†“์•˜๋Š”๋ฐ ํ™•์‹คํžˆ ์ด๋Ÿฐ ์‹์œผ๋กœ ํ•ด์•ผ ํ•  ์ผ๋“ค์ด ๊ฐ€์‹œ์ ์œผ๋กœ ๋ณด์ด๋‹ˆ๊นŒ ์ผ ์ง„ํ–‰์ด ์ฐฉ์ฐฉ ์ด๋ฃจ์–ด์ ธ์„œ ์ข‹์•˜๋‹ค. ์•ž์œผ๋กœ๋„ ๋ฌด์Šจ ํ”„๋กœ์ ํŠธ๋ฅผ ํ•˜๋“  ์ด๋Ÿฐ ์‹์œผ๋กœ ์ผ์ • ๊ด€๋ฆฌ๋ฅผ ํ•˜๋ฉด ํ˜‘์—…ํ•  ๋•Œ ํŠนํžˆ ๋น›์„ ๋ฐœํ•  ๊ฒƒ ๊ฐ™๋‹ค. 

์šฐ์„  ํ–„๋””์˜ ์ปดํ“จํ„ฐ๋กœ npx create react app์„ ํ•ด์„œ boilerplate๋ฅผ ์ƒ์„ฑํ–ˆ๋‹ค. ํ•„์š” ์—†๋Š” ํŒŒ์ผ, ์ฃผ์„, ์ฝ”๋“œ ๋“ฑ์€ ์ง€์› ๋‹ค. ๋˜ prettierrc ํŒŒ์ผ๋„ ๋งŒ๋“ค์—ˆ๋‹ค. lint ์„ค์ •์€ ํ• ๊นŒ ๊ณ ๋ฏผํ•˜๋‹ค๊ฐ€ ๋„ˆ๋ฌด ๋ณต์žกํ•ด์งˆ ๊ฒƒ ๊ฐ™์•„์„œ ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ์ œ์™ธํ–ˆ๋‹ค. ์นธ์ด ์—์–ด๋น„์—”๋น„ lint๋ฅผ ์ผ๋‹ค๊ฐ€ ๋„ˆ๋ฌด ๋นก์„ธ์„œ ๊ฐœ๋ฐœ์„ ์ ‘์„ ๋ป” ํ–ˆ๋‹ค๋Š” (ใ…‹ใ…‹ใ…‹) ์ด์•ผ๊ธฐ๋ฅผ ๋“ฃ๊ณ  ์ด๊ฑด ๋‹ค์Œ์— ๊ฑด๋“œ๋ฆฌ๊ธฐ๋กœ ํ–ˆ๋‹ค. 

๊ธฐ๋ณธ์ ์ธ ์…‹์—…์„ ๋งˆ์นœ ํ›„, ์ด์ œ Styled Components๋ฅผ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ณต๋ถ€๊ฐ€ ์ข€ ํ•„์š”ํ–ˆ๋‹ค. Sass๋ฅผ ์ ์šฉํ• ์ง€ Module์„ ์ ์šฉํ• ์ง€์— ๋Œ€ํ•œ ๊ณ ๋ฏผ์ด ๋งŽ์•˜๋Š”๋ฐ ํฌ๋กฑ์ด Styled Components๋ฅผ ์ถ”์ฒœํ•ด ์ฃผ์…”์„œ ์ด๊ฒƒ์„ ํ•˜๊ธฐ๋กœ ํ–ˆ๋‹ค. ๋‚˜๋Š” ์˜ˆ์ „์— ํ”„๋กœ์ ํŠธ์—์„œ ์ ์šฉํ•ด ๋ณธ ์ ์ด ์žˆ์—ˆ๋Š”๋ฐ ์ •๋ง ์•„์ฃผ ๊ธฐ์ดˆ์ ์ธ ์‚ฌ์šฉ๋ฒ•๋งŒ ์•Œ๊ณ  ์ผ๋ถ€์˜ ๊ธฐ๋Šฅ๋งŒ ์“ด ๊ฒƒ์ด์–ด์„œ ์ถ”๊ฐ€์ ์ธ ๊ณต๋ถ€๊ฐ€ ํ•„์š”ํ–ˆ๋‹ค. ์ „์—ญ ์Šคํƒ€์ผ๋ง์„ ์œ„ํ•ด createGlobalStyle์ด๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ–ˆ๋‹ค. Styled Components๋ฅผ ๋ฐฐ์šฐ๋ฉด์„œ Tagged Templates๋ผ๋Š” ๊ฒƒ๋„ ํ•จ๊ป˜ ์•Œ๊ฒŒ ๋˜์—ˆ๋‹ค.

 

Template literals (Template strings) - JavaScript | MDN

Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, for string interpolation with embedded expressions, and for special constructs called tagged templates.

developer.mozilla.org

MDN์˜ ์„ค๋ช…์— ๋”ฐ๋ฅด๋ฉด Tagged Templates๋ž€ Template literals์˜ ์ง„๋ณด๋œ ํ˜•ํƒœ๋ผ๊ณ  ํ•œ๋‹ค. ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํ•จ์ˆ˜๋กœ template literal์„ ๋ถ„์„ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด๋‹ค. ์–ด๋–ป๊ฒŒ ๋ถ„์„ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฑธ๊นŒ? ์ฒ˜์Œ์—๋Š” ์„ค๋ช…๋งŒ ๋“ฃ๊ณ  ์ž˜ ์™€๋‹ฟ์ง€ ์•Š์•˜๋‹ค.

const name = 'Millie'

function greet() {
	return 0;
}

greet`Hello, nice to meet you ${name}!`

์ผ๋ฐ˜์ ์œผ๋กœ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•  ๋•Œ greet() ์ด๋Ÿฐ ์‹์œผ๋กœ ๊ด„ํ˜ธ๋ฅผ ๋ถ™์—ฌ์„œ ์‹คํ–‰ํ•˜์ง€๋งŒ, ๊ด„ํ˜ธ ๋Œ€์‹ ์— ๋ฌธ์ž์—ด์„ ๋ถ™์—ฌ์„œ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด๋‹ค! ์ด๊ฒƒ์ด ๋ฐ”๋กœ Tagged Literal. ๋ฆฌํ„ฐ๋Ÿด์— ํƒœ๊ทธ๋ฅผ ํ•ด ์ฃผ๋Š” ๊ฒƒ์ด๋‹ค. ์œ„์™€ ๊ฐ™์ด ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•  ๊ฒฝ์šฐ greet ํ•จ์ˆ˜์˜ ๋ฆฌํ„ด๊ฐ’์ธ 0์ด ๋ฆฌํ„ด์ด ๋œ๋‹ค. 

์œ„์™€ ๊ฐ™์ด Tagged Literal ๋ฌธ๋ฒ•์„ ํ™œ์šฉํ•˜๋ฉด ๋ฌธ์ž์—ด์„ ๋ถ„์„ํ•ด์„œ ๋‹จ์–ด์˜ ์ˆœ์„œ๋ฅผ ๋ณ€๊ฒฝํ•˜๊ฑฐ๋‚˜, ๋‹จ์–ด๋ฅผ ์ œ๊ฑฐํ•˜๊ฑฐ๋‚˜ ํ˜น์€ ๋ณ€์ˆ˜์˜ ์œ„์น˜๋„ ์‰ฝ๊ฒŒ ์˜ฎ๊ธธ ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค. Tagged Literal์„ ์“ฐ์ง€ ์•Š๋Š”๋‹ค๋ฉด ์ •๊ทœํ‘œํ˜„์‹์ด๋‚˜ ๋‹ค๋ฅธ ๋ฉ”์„œ๋“œ๋ฅผ ํ™œ์šฉํ•ด์•ผ ํ–ˆ๋Š”๋ฐ ES6์— ์ด ๋ฌธ๋ฒ•์ด ๋“ฑ์žฅํ•˜์—ฌ ๋ฌธ์ž์—ด์„ ๋‹ค๋ฃฐ ๋•Œ ์ข€ ๋” ์ˆ˜์›”ํ•˜๊ฒŒ ๋œ ๊ฒƒ์ด๋‹ค. 

ํ•จ์ˆ˜์˜ ์ฒซ ๋ฒˆ์งธ ์ธ์ž๋Š” ๋ฌธ์ž์—ด์ด ์ž˜๋ ค์„œ ๋ฐฐ์—ด๋กœ ๋“ค์–ด๊ฐ€๊ณ , ๋‘ ๋ฒˆ์งธ ์ธ์ž๋ถ€ํ„ฐ๋Š” ๋ณ€์ˆ˜์ด๋‹ค. 

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

CodeSquad Day 74 : Team Project 2 - Day 4  (2) 2022.04.21
CodeSquad Day 73 : Team Project 2  (1) 2022.04.20
CodeSquad Day 71 : Team Project 2  (0) 2022.04.18
CodeSquad Day 70 : Team Project Week 2  (0) 2022.04.16
CodeSquad Day 69 : Team Project Week 2  (0) 2022.04.15