Skip to content

Latest commit

ย 

History

History

quick-start

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
ย 
ย 

Quick Start


Note

'Quick Start' ์ฑ•ํ„ฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋‚ด์šฉ์„ ๋‹ค๋ฃน๋‹ˆ๋‹ค.

  • ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค๊ณ  ์ค‘์ฒฉํ•˜๋Š” ๋ฐฉ๋ฒ•
  • ๋งˆํฌ์—…๊ณผ ์Šคํƒ€์ผ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•
  • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ฐ์ดํ„ฐ๋ฅผ ํ‘œ์‹œํ•˜๋Š” ๋ฐฉ๋ฒ•
  • ์กฐ๊ฑด์— ๋”ฐ๋ผ ๋˜๋Š” ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ Œ๋”๋งํ•˜๋Š” ๋ฐฉ๋ฒ•
  • ์ด๋ฒคํŠธ์— ์‘๋‹ตํ•˜๊ณ  ํ™”๋ฉด์„ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๋ฐฉ๋ฒ•
  • ์ปดํฌ๋„ŒํŠธ ๊ฐ„์— ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ ํ•˜๋Š” ๋ฐฉ๋ฒ•

Quick Start

  1. React components are JavaScript functions that return markup:

    • ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํ•จ์ˆ˜๋ผ๋Š” ์ ์ด ํ•ต์‹ฌ์ธ ๋ฌธ์žฅ์œผ๋กœ, ํ•จ์ˆ˜๋ผ๋Š”๊ฑธ ์ƒ๊ธฐ์‹œํ‚ค๋Š” ๋ฌธ์žฅ!
      -(https://www.youtube.com/watch?v=MSq_DCRxOxw&t=141s) SOLID ๊ด€๋ จ์˜์ƒ ์ปดํฌ๋„ŒํŠธ ์ •๋ฆฌ์‹œ ์ฐธ๊ณ ํ•˜๊ธฐ ์ข‹์€ ์˜์ƒ์œผ๋กœ ๊ณต์œ ํ•ด์ฃผ์‹ฌ๐Ÿ’™
  2. JSX lets you put markup into JavaScript. Curly braces let you โ€œescape backโ€ into JavaScript so that you can embed some variable from your code and display it to the user. For example, this will display user.name:

    • JSX๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๊ฑด ๊ฒฐ๊ตญ jsํ™•์žฅํŒŒ์ผ, ๊ฒฐ๊ตญ ๋ฆฌ์•กํŠธ์—์„œ js๋กœ ๋ฐ”๊ฟ”๋Š”์ฃผ๋Š”๊ฒƒ

๐Ÿคทโ€โ™€๏ธ ํ† ์˜

  • Q: '? {isLoggedIn && }' ์ฒ˜๋Ÿผ ์กฐ๊ฑด๋ถ€ ๊ตฌ๋ฌธ์ด ๋‹ค๋ฅธ ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ๋Š” ์–ด๋–คํ˜•์‹์œผ๋กœ ์‚ฌ์šฉ ๋˜๋Š”๊ฐ€?
  • A: (Vue) ์—์„œ๋Š” v-if, v-else-if ์ด๋Ÿฐ์‹์œผ๋กœ ์‚ฌ์šฉ
  • Q: ํ•™์Šต๋ฐฉ๋ฒ•์€ ์–ด๋–ค์‹์ธ๊ฐ€?
  • A: ๋Œ€๋ถ€๋ถ„ ๋”ฐ๋ผ์น˜๋Š”๊ฒƒ์„ ์šฐ์„ ์œผ๋กœ ํ•˜๊ณ  ๊ทธํ›„์— ์ด๋ก ์„ ํ™•์ธํ•˜๋Š” ๋ฐฉ์‹, ์ด๋ก ๋จผ์ € ์ฝ๊ธฐ์—” ๋ถ€๋‹ด์Šค๋Ÿฌ์šด๋ฉด์ด ์žˆ์Œ


Tutorial: Tic-Tac-Toe

  1. In React, a component is a piece of reusable code that represents a part of a user interface. Components are used to render, manage, and update the UI elements in your application.

    • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ UI์ฒ˜๋Ÿผ ์žฌ์‚ฌ์šฉํ•œ๊ฒƒ์ด ํ˜์‹ ์ 
    • ์ปดํฌ๋„ŒํŠธ๋ž€ ๋ฌด์—‡์ธ๊ฐ€์— ๋Œ€ํ•ด ์ƒ๊ฐํ•ด ๋ณธ ์ ์ด ์—†๋Š”๋ฐ, ๊ฐ„๋‹จ๋ช…๋ฃŒํ•œ ์ •๋ฆฌ๋ผ์„œ ์ธ์ƒ ๊นŠ์Œ
  2. In React, itโ€™s conventional to use onSomething names for props which represent events and handleSomething for the function definitions which handle those events.

    • ์Šคํ„ฐ๋”” 1์ฃผ์ฐจ์— ๊ฐ๊ธฐ ๋‹ฌ๋ผ ์ปจ๋ฒค์…˜์„ ๋งž์ถ”๊ธฐ ์–ด๋ ต๋‹ค๊ณ  ์–ธ๊ธ‰ํ–ˆ๋Š”๋ฐ, ๊ณต์‹๋ฌธ์„œ์— ์ด๋Ÿฐ ๋ถ€๋ถ„(on, handle)์„ ์ •ํ•ด์ค˜์„œ ์ด ๊ธฐ์ค€์„ ๋”ฐ๋ฅด๋ฉด ์ข‹๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐ
    • ๋‹ค๋ฅธ ์‚ฌ๋žŒ๊ณผ ํ˜‘์—…ํ•˜์—ฌ ํ•จ์ˆ˜๋ช… ์งค ๋•Œ ๋งค๋ฒˆ on๊ณผ handle์ด ์„ž์ด๊ฒŒ ๋˜์–ด์„œ ๋‘˜ ์ค‘ ํ•˜๋‚˜๋กœ ํ†ต์ผํ•ด์•ผ ํ•˜๋‚˜ ๊ณ ๋ฏผํ–ˆ์—ˆ๋Š”๋ฐ, ์•ž์œผ๋กœ๋Š” ์ด๊ฑธ ๊ธฐ์ค€์œผ๋กœ ๋‘๊ณ  ์ž‘์—…ํ•ด์•ผ๊ฒ ๋‹ค ์ƒ๊ฐ
  3. Immutability makes it very cheap for components to compare whether their data has changed or not avoid redundant state. Simplifying what you store in state reduces bugs and makes your code easier to understand.

    • ๋ถˆ๋ณ€์„ฑ์˜ ์žฅ์  2๊ฐ€์ง€๋กœ ์ตœ์ ํ™” ์™€ ๋” ์‰ฌ์šด ์ฝ”๋“œ์˜ ์ดํ•ด๊ฐ€ ์žˆ์Œ
    • ๋ถˆ๋ณ€์„ฑ์„ ์ง€ํ‚ค๋ฉด์„œ ์ž‘์—…ํ•ด์•ผ ํ•œ๋‹ค๊ณ  ์ธ์‹์€ ํ•˜๊ณ  ์žˆ์—ˆ๋Š”๋ฐ, ๊ทธ ์ด์œ  ์ค‘ ํ•˜๋‚˜๊ฐ€ ์ตœ์ ํ™”์˜€๋‹จ ๊ฑธ ์•Œ๊ฒŒ๋จ
  4. JavaScript supports closures which means an inner function (e.g. handleClick) has access to variables and functions defined in a outer function (e.g. Board). The handleClick function can read the squares state and call the setSquares method because they are both defined inside of the Board function.

    • ํด๋กœ์ €๋ฅผ ์ง€์›ํ•˜๋ฏ€๋กœ ๋‚ด๋ถ€ํ•จ์ˆ˜๊ฐ€ ์™ธ๋ถ€ ํ•จ์ˆ˜์— ์ •์˜๋œ ๋ณ€์ˆ˜ ๋ฐ ํ•จ์ˆ˜์— ์—‘์„ธ์Šคํ•  ์ˆ˜ ์žˆ์Œ
    • ํด๋กœ์ €๋ฅผ ๋ช…ํ™•ํžˆ ์„ค๋ช…ํ•ด์ค˜์„œ ์ข‹์Œ
  5. You donโ€™t need useState for thisโ€”you already have enough information to calculate it during rendering:

    • ๊ฐœ๋ฐœ์„ ์ง„ํ–‰ํ•˜๋‹ค ๋ณด๋ฉด useState๋ฅผ ๋‚จ๋ฐœํ•˜๋Š” ๊ฒฝ์šฐ ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”๋ฐ, ๋‚จ๋ฐœ์—†์ด ํ•˜๋Š”๋ฐฉ๋ฒ•์„ ๊ณ ๋ คํ•˜๋Š”๊ฒƒ์ด ์ตœ์ ํ™”์— ์ข‹๋‹ค๊ณ  ์ƒ๊ฐ
  6. Thereโ€™s no reason for you to store both of these in state. In fact, always try to avoid redundant state. - ์ƒํƒœ์˜ ์ค‘๋ณต์„ ํ”ผํ•˜๋Š”๊ฒŒ ๊ฐ„๋‹จํ•œ ์ตœ์ ํ™” ๋ฐฉ๋ฒ•์ด๋ผ๊ณ  ์ƒ๊ฐ



Thinking in React

  1. One such technique is theย single responsibility principle, that is, a component should ideally only do one thing.

    • ๊ธ‰ํ•˜๊ฒŒ ์ž‘์—…์‹œ ํ•œ ์ปดํฌ๋„ŒํŠธ์— ์—ฌ๋Ÿฌ๊ฐ€์ง€๋ฅผ ๋ชฐ์•„ ๋„ฃ๋Š๋ผ ์ด๋Ÿฐ ์›์น™์„ ๊นจ๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๋‹ค๊ณ  ๋Š๋‚Œ, ๋ฆฌํŒฉํ† ๋ง ๋‹จ๊ณ„์—์„œ ์ด๋ฅผ ๊ฐœ์„ ํ•จ
  2. Itโ€™s often easier to build the static version first and add interactivity later. Building a static version requires a lot of typing and no thinking, but adding interactivity requires a lot of thinking and not a lot of typing.

    • UI๋ฅผ ๋งŒ๋“ค๊ณ  ํ•˜๋Š”๊ฒŒ ํ†ต์ƒ์ ์ธ ์ˆœ์„œ๊ตฌ๋‚˜..
  3. If your JSON is well-structured, youโ€™ll often find that it naturally maps to the component structure of your UI. Thatโ€™s because UI and data models often have the same information architectureโ€”that is, the same shape. Separate your UI into components, where each component matches one piece of your data model.

    • api๊ฐ€ ํ™”๋ฉด์— ์ตœ์ ํ™” ๋˜์„œ ์ „๋‹ฌ ๋ฐ›์ง€ ์•Š์•„์„œ ์ปดํฌ๋„ŒํŠธ ๊ตฌ์กฐ์™€ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋งคํ•‘์ด ๋˜๋‚˜? ๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ฌ
    • Does it remain unchanged over time? If so, it isnโ€™t state.
    • Is it passed in from a parent via props? If so, it isnโ€™t state.
    • Can you compute it based on existing state or props in your component? If so, it definitely isnโ€™t state!
    • ๋ฆฌ์•กํŠธ์—์„œ ์ƒํƒœ๋ผ๋Š”๊ฑด ์ค‘์š”ํ•œ ๊ฐœ๋… ์ด๊ฑธ ์ž˜ ๊ตฌ๋ถ„ํ•œ๋‹ค๋ฉด ์ตœ์†Œํ•œ์˜ ์ตœ์ ํ™”๋œ ์ฝ”๋“œ๋ฅผ ๋งž์ถœ ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐ

๐Ÿคทโ€โ™€๏ธ ํ† ์˜

  • Q: (1๋ฒˆ ๊ด€๋ จ) ์–ด๋–ค์‹์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ ํ•˜๋Š”๊ฐ€?
  • A: ๋Œ€๋ถ€๋ถ„ ์ฝ”๋“œ ์ž‘์„ฑ ํ›„์— ์ชผ๊ฐœ๋Š”ํŽธ, ์ž‘๊ฒŒ ๋งŒ๋“ ํ›„ ์กฐ๋ฆฝํ•˜๋Š” ๋ฐฉ์‹์ด ์˜คํžˆ๋ ค ์–ด๋ ต๊ฒŒ ๋Š๊ปด์งˆ๋•Œ๊ฐ€ ์žˆ์Œ
  • A:

    You can either build โ€œtop downโ€ by starting with building the components higher up in the hierarchy (like FilterableProductTable) or โ€œbottom upโ€ by working from components lower down (like ProductRow). In simpler examples, itโ€™s usually easier to go top-down, and on larger projects, itโ€™s easier to go bottom-up. ์ด๋Ÿฐ ๋ฐฉ๋ฒ•๋„ ์กด์žฌํ•˜๊ณ , ์ฝ”๋“œ ์ž‘์„ฑ์„ ํ•ด๋ณด๋‹ˆ ํ•˜ํ–ฅ์‹์ด ๋”์‰ฝ๋‹ค๊ณ  ๋Š๊ปด์ง

  • Q: (2๋ฒˆ ๊ด€๋ จ) ๋‹ค๋ฅธ๋ถ„๋“ค์€ ์–ด๋–ค ์ˆœ์„œ๋กœ ์ง„ํ–‰ ๋˜๋Š”๊ฐ€?
  • A: Api๊ฐ€ ์—†๋Š”์ƒํƒœ์—์„œ ๋””์ž์ธํ•˜๊ณ  ๋ฒก์—”๋“œ ๊ฐœ๋ฐœ ์™„๋ฃŒ ํ›„ ๊ธฐ๋Šฅ ์ด์–ด ๋ถ™์ž„
  • Q: (3๋ฒˆ ๊ด€๋ จ) ๋ฐฑ์—”๋“œ์™€ ํ˜‘์—…ํ•˜์—ฌ api์™€ ํ™”๋ฉด์„ ๋งž์ถ”๋Š” ํŽธ์ธ๊ฐ€? ์•„๋‹ˆ๋ฉด ๊ทธ๋ƒฅ ์ฃผ๋Š”๋Œ€๋กœ ํ•˜๋Š” ํŽธ์ธ๊ฐ€?
  • A: ํ•„์š”ํ•œ๊ฐ’๋งŒ ์ฃผ๋ฉด ๊ทธ๊ฑฐ์— ๋งž์ถฐ์„œ ๊ฐ€๊ณตํ•˜๋Š”ํŽธ์ด๋‹ค.
  • A: ๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ์ž๊ฐ€ ํ™”๋ฉด์„ ์–ผ๋‚˜๋งˆ ๊ณ ๋ คํ•ด์„œ ์ฃผ๋Š๋ƒ์— ๋”ฐ๋ผ์„œ ๋‹ค๋ฅด๋‹ค. ํ”„๋กœ์ ํŠธ ํ•˜๋ฉด์„œ ๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ์ž์™€ ๋งŽ์€ ํ˜‘์—…์ด ํ•„์š”ํ•˜๋‹ค.

    ๐Ÿ’ก ๋ฐœํ‘œ์ž๋‹˜ Tip.
    • ๊ณต์‹๋ฌธ์„œ ์ค‘๊ฐ„์ค‘๊ฐ„ ๋ชจ๋ฅด๋Š” ๋‚ด์šฉ์ด ์žˆ๋”๋ผ๊ณ  ๋’ค์ชฝ์—์„œ ์„ค๋ช…ํ•ด์ฃผ๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์œผ๋‹ˆ ๋„˜์–ด๊ฐ€๋Š”๊ฒƒ๋„ ์ข‹๋‹ค!