Framework/React ์™„๋ฒฝ ๊ฐ€์ด๋“œ

[React ์™„๋ฒฝ ๊ฐ€์ด๋“œ] section 3 : ๋ฆฌ์•กํŠธ ๊ธฐ์ดˆ ๋ฐ ์‹ค์Šต ์ปดํฌ๋„ŒํŠธ

yuri lee 2022. 9. 6. 23:11
๋ฐ˜์‘ํ˜•
์ด ๊ธ€์€ udemy์˜ React ์™„๋ฒฝ ๊ฐ€์ด๋“œ with Redux, Next.js, TypeScript ๊ฐ•์ขŒ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ •๋ฆฌํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค.

24. Module Content

  • React Core Syntax & JSX
  • Working with Components
  • Working with Data

25. ์ปดํฌ๋„ŒํŠธ๋ž€ ๋ฌด์—‡์ธ๊ฐ€? ์™œ ๋ฆฌ์•กํŠธ๋Š” ์ปดํฌ๋„ŒํŠธ์˜ ์ „๋ถ€๋ผ๊ณ  ํ•˜๋Š”๊ฐ€?

  • you will be able to focus on your core business logic that makes up your application instead of having to focus on the actual steps of updating the page when something happens somewhere.
  • React is a JavaScript library for building user interfaces
  • HTML, CSS & JavaScript are about building user interfaces as well.
  • React makes building complex, interactive and reactive user interfaces simpler
  • React is all about components.

What is Components?

  • Because all user interfaces in the end are made up of components

Why components?

  • Reusablility - Don't repoeat yourself
  • Separation of Concerns - Don't do too many things in one and the same place (function)
  • conclusion : Split big chunks of code into multiple smaller functions

26. ๋ฆฌ์•กํŠธ ์ฝ”๋“œ๋Š” "์„ ์–ธ์  ๋ฐฉ์‹"์œผ๋กœ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!

  1. React allows you to create re-usable and reactive components consisting of HTML and JavaScript (and CSS)
  2. Declarative Approach
    (๋ฐ˜๋“œ์‹œ "ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ"์„ ์•Œ์•„์•ผ ํ• ๊นŒ? ๊ธ€์—์„œ ๋” ์ž์„ธํ•œ ๋‚ด์šฉ์„ ์‚ดํŽด๋ณผ ์ˆ˜ ์žˆ๋‹ค.  )
  3. Define the desired target state(s) and let React figure out the actual JavaScript DOM instructions

27. A Note About New React Projects & NodeJS

  • DON'T download NodeJS version 17! Because at the moment, the created projects won't work with that version.
    • ์ฐธ๊ณ ๋กœ ๋‚˜๋Š” ๊ฒฝ์šฐ nvm ์„ ์‚ฌ์šฉํ•˜์—ฌ v16.17.0 ๋ฒ„์ „์„ ์ถ”๊ฐ€ ์„ค์น˜ํ•˜์—ฌ ์‚ฌ์šฉํ•จ.

28. ์ƒˆ๋กœ์šด ๋ฆฌ์•กํŠธ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ

  • nodeJs : ๋ธŒ๋ผ์šฐ์ € ๋ฐ–์—์„œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋Ÿฐํƒ€์ž„ ํ™˜๊ฒฝ์ด๋‹ค.
  • create react app ํˆด์„ ์œ„ํ•ด ์ด node.js๊ฐ€ ํ•„์š”ํ•˜๋‹ค.
  • https://nodejs.org/en/ ๋ฅผ ํ†ตํ•ด ์ตœ์‹ ๋ฒ„์ „ ์„ค์น˜

29. ์‹œ์ž‘ ํ”„๋กœ์ ํŠธ

  • ์ฒจ๋ถ€ํŒŒ์ผ & github ์ฐธ๊ณ 

30. ํ‘œ์ค€ ๋ฆฌ์•กํŠธ ํ”„๋กœ์ ํŠธ ๋ถ„์„ํ•˜๊ธฐ

// index.js
import ReactDOM from 'react-dom/client';

import './index.css';
import App from './App';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
  • index.html ํŒŒ์ผ์— div ํƒœ๊ทธ๊ฐ€ ์žˆ๊ณ , ์ด div ํƒœ๊ทธ์— ๋ฌด์—‡์„ ๋ Œ๋”๋ง ํ•ด์•ผ ํ•˜๋Š”์ง€ ์•Œ๋ฆฐ๋‹ค.
// package.json
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
  • react, react-dom ์€ Rect ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ๋ถ€ํ„ฐ ๊ฐ™์€ ์˜์กด์„ฑ์„ ๊ฐ–๋Š”๋‹ค.

Tips

  • import ์‹œ third party libraries or ๋งŒ๋“  js ํŒŒ์ผ ์ค‘ ํ•˜๋‚˜๋ผ๋ฉด .js๋Š” ์ƒ๋žตํ•ด๋„ ๋œ๋‹ค.

31. JSX ์†Œ๊ฐœ

function App() {
  return (
    <div>
      <h2>Let's get started!</h2>
    </div>
  );
}

export default App;
  • JSX๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ XML์„ ์˜๋ฏธํ•œ๋‹ค. HTML์€ XML์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ์Œ

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

  • App()์„ ๊ฒ€์ƒ‰ํ•œ ๊ฒฐ๊ณผ ๊ธฐ์กด ์ž‘์„ฑํ•œ ์ฝ”๋“œ๋ณด๋‹ค ๋‹ค๋ฅธ ์ฝ”๋“œ๋“ค์ด ์ถ”๊ฐ€๋œ ๋ชจ์Šต์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

32.๋ฆฌ์•กํŠธ ์ž‘๋™ ๋ฐฉ์‹

์ปดํฌ๋„ŒํŠธ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์ž์ฒด html ์š”์†Œ์ผ ๋ฟ์ด๋‹ค.

  1. React allows you to create re-usable and reactive components consisting of HTML and JavaScript (and CSS)
  2. Declarative Approach (์„ ์–ธํ˜• ์ ‘๊ทผ / How ๋ณด๋‹ค What์— ์ดˆ์ !๐Ÿ’จ )
  3. Define the desired tagert state(s) and let React figure out the actual JavaScript DOM instructions
function App() {
  return (
    <div>
      <h2>Let's get started!</h2>
      <p>This is also visible! </p>
    </div>
  );

}
export default App;

→ ์„œ๋ฒ„๋Š” ์ž๋™์„ ๋ณ€ํ™”๋ฅผ ์•Œ์•„์ฑ„๊ณ  ์—…๋ฐ์ดํŠธ ํ•œ๋‹ค.

→ ์ด๋Ÿฌํ•œ ์ด์œ ๋“ค๋กœ ๋ฆฌ์•กํŠธ๋Š” ์ปดํฌ๋„ŒํŠธ๋ผ๋Š” ๊ฐœ๋…์„ ๋„์ž…ํ–ˆ๋‹ค.

33. ์ฒซ ๋ฒˆ์งธ ์‚ฌ์šฉ์ž ์ง€์ • ์ปดํฌ๋„ŒํŠธ ๋งŒ๋“ค๊ธฐ

  • ํ•œ ์ปดํฌ๋„ŒํŠธ๋‹น ํ•˜๋‚˜์˜ ํŒŒ์ผ์„ ๊ฐ–๋„๋ก ์—ฐ์Šตํ•˜๋Š” ๊ฒŒ ์ข‹๋‹ค.
  • ๋ฆฌ์•กํŠธ์— ์žˆ๋Š” ์ปดํฌ๋„ŒํŠธ๋Š” ๋‹จ์ง€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ํ•จ์ˆ˜์ผ ๋ฟ์ด๋‹ค. (Just javascript function!)
const root = ReactDOM.createRoot(document.getElementById('root'));

→ ์ด ์ž‘์—…์€ ๋ฃจํŠธ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์œ„ํ•ด ํ•œ๋ฒˆ๋งŒ ํ•˜๋Š” ์ž‘์—…์ด๋‹ค.

import './App.css';
import ExpenseItem from './components/ExpenseItem';

function App() {
  return (
    <div>
      <h2>Let's get started!</h2>
      <ExpenseItem>This is also visible!</ExpenseItem>
    </div>
  );
}

export default App;

→ ์†Œ๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•˜๋Š” ์š”์†Œ๋Š” ๋‚ด์žฅ๋œ html ์š”์†Œ์ด๊ณ , ๋Œ€๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•˜๋Š” ์š”์†Œ๋Š” ๊ฐœ๋ฐœ์ž๊ฐ€ ์ •์˜ํ•œ ์š”์†Œ์ด๋‹ค.

34.๋” ๋ณต์žกํ•œ JSX ์ฝ”๋“œ ์ž‘์„ฑ

  • ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ทœ์น™! JSX ์ž‘์„ฑ์‹œ ๋ฐ˜๋“œ์‹œ ํ•œ๊ฐœ์˜ ๋ฃจํŠธ ์š”์†Œ๋ฅผ ๊ฐ€์ ธ์•ผ ํ•œ๋‹ค.
  • ๊ฐ€๋…์„ฑ์„ ๊ณ ๋ คํ•˜์—ฌ ๊ด„ํ˜ธ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ๋‹ค. ()

35. ๊ธฐ๋ณธ CSS ์Šคํƒ€์ผ ์ถ”๊ฐ€

  • ์ผ๋ฐ˜์ ์ธ html์—์„œ๋Š” class๋ฅผ ์‚ฌ์šฉํ•˜์ง€๋งŒ, jsx์—์„œ๋Š” className์„ ์‚ฌ์šฉํ•œ๋‹ค.
  • class๋Š” javascript์—์„œ ์˜ˆ์•ฝ๋œ ๋‹จ์–ด์ด๊ธฐ ๋•Œ๋ฌธ!

36. JSX์—์„œ ๋™์  ๋ฐ์ดํ„ฐ ์ถœ๋ ฅ ๋ฐ ํ‘œํ˜„์‹ ์ž‘์—…ํ•˜๊ธฐ

  • ์ค‘๊ด„ํ˜ธ (Curly braces)๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
  • ๋ชจ๋“  data ๊ฐ์ฒด์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋‚ด์žฅ ๋ฉ”์†Œ๋“œ์ธ toISOString์„ ํ˜ธ์ถœํ•ด์„œ ๋ฌธ์ž์—ด๋กœ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๋‹ค.

37. "props"๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ์ „๋‹ฌํ•˜๊ธฐ

  • ๊ธฐ๋ณธ์ ์œผ๋กœ ์šฐ๋ฆฌ๋งŒ์˜ ์‚ฌ์šฉ์ž ์ง€์ • html ์š”์†Œ์ฒ˜๋Ÿผ ์†์„ฑ์„ ๊ตฌ์ถ•ํ•˜๊ณ  ์žˆ๋‹ค. ๋ฆฌ์•กํŠธ๋กœ๋„ ์‚ฌ์šฉ์ž ์ง€์ • ์ปดํฌ๋„ŒํŠธ๋„ ์†์„ฑ์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š”๋ฐ, ๋ฆฌ์•กํŠธ์—์„œ ์ด ๊ฐœ๋…์€ ์†์„ฑ ๋Œ€์‹  props ๋ผ๊ณ  ๋ถˆ๋ฆฐ๋‹ค. 
  • props ๋Š” properties ๋ฅผ ๋‚˜ํƒ€๋‚ธ ๊ฒƒ
  • props๊ฐ์ฒด์—์„œ ํ‚ค์™€ ๋ฐธ๋ฅ˜๋กœ ์ด๋ฃจ์–ด์ง„ ํŒŒ์ผ ํฌ๋งท์„ ๊ฐ–๊ณ  ์žˆ๋‹ค.
  • ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค. (์ค‘์š” ๐Ÿ’ฏ ๐Ÿ’ฏ ๐Ÿ’ฏ)
function ExpenseItem(props) {
    return (
        <div className='expense-item'>
            <div>{expenseDate.toISOString}</div>
            <div className='expense-item__description'>
                <h2>{props.title}</h2>
                <div className='expense-item__price'>${expenseAmount}</div>
            </div>
        </div>
    )
}

→ props ์˜ ๊ฐ’์„ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ์Œ! ๐Ÿคง

      <ExpenseItem
        title={expenses[0].title}
        amount={expenses[0].amount}
        date={expenses[0].amount}>
      </ExpenseItem>

→ ํ‚ค๋Š” ์ •์˜๋ค ์†์„ฑ ์ด๋ฆ„์ธ title, amount, date๊ฐ€ ๋  ๊ฒƒ์ด๊ณ , ๋ฐธ๋ฅ˜๋Š” ์—ฌ๊ธฐ์„œ ์„ค์ •๋œ ๊ฐ’์ด ๋  ๊ฒƒ์ด๋‹ค.

 

38. ์ปดํฌ๋„ŒํŠธ์— "์ผ๋ฐ˜" JavaScript ๋…ผ๋ฆฌ ์ถ”๊ฐ€ํ•˜๊ธฐ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์—ฌ๋Ÿฌ ์ปดํฌ๋„ŒํŠธ๋กœ ๋ถ„ํ• ํ•˜๊ธฐ

function ExpenseItem(props) {
  const month = props.date.toLocaleString("en-US", { month: "long" });
  const day = props.date.toLocaleString("en-US", { day: "2-digit" });
  const year = props.date.getFullYear();

  return (
    <div className="expense-item">
      {/* <div>{props.date.toISOString()}</div> */}
      <div>
        <div>{month}</div>
        <div>{year}</div>
        <div>{day}</div>
      </div>
      <div className="expense-item__description">
        <h2>{props.title}</h2>
        <div className="expense-item__price">${props.amount}</div>
      </div>
    </div>
  );
}
export default ExpenseItem;

39.  ์ปดํฌ๋„ŒํŠธ๋ฅผ ์—ฌ๋Ÿฌ ์ปดํฌ๋„ŒํŠธ๋กœ ๋ถ„ํ™œํ•˜๊ธฐ

  • convention of naming 
  • ์—ฌ๋‹ซ๋Š” ํƒœ๊ทธ์— ์ปจํ…์ธ  ์—†๋Š” ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žˆ๋‹ค๋ฉด ์ž๋™์œผ๋กœ ๋‹ซํžˆ๋Š” ์š”์†Œ๋กœ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. 
<ExpenseDate><ExpenseDate />
<ExpenseDate /> // O

40.  ์—ฐ์Šตํ•˜๊ธฐ : ๋ฆฌ์•กํŠธ ๋ฐ ์ปดํฌ๋„ŒํŠธ ๊ธฐ๋ณธ ์‚ฌํ•ญ

  • pass ! 

41.  ์—ฐ์Šตํ•˜๊ธฐ : ๋ฆฌ์•กํŠธ ๋ฐ ์ปดํฌ๋„ŒํŠธ ๊ธฐ๋ณธ ์‚ฌํ•ญ(์ •๋‹ต)

  • ๋‘ ๊ฐœ์˜ ์ƒˆ๋กœ์šด ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ถ”๊ฐ€ํ–ˆ๊ณ , props๋ฅผ ์ด์šฉํ•ด์„œ ์ปดํฌ๋„ŒํŠธ์— ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌํ–ˆ๊ณ , css ๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ธฐ๋ณธ์ ์ธ ์Šคํƒ€์ผ์„ ์ถ”๊ฐ€ํ–ˆ๋‹ค. 

42.  composition์˜ ๊ฐœ๋… ("children prop")

  • App.js ์—์„œ๋Š” Expenses ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , Expenses ์—์„œ๋Š” ExpenseItem์„ ์‚ฌ์šฉํ•œ๋‹ค. 
  • Generally, this approach of building a user interface from smaller building blocks is called composition.
  • ๊ธฐ์กด์˜ border-radius, box-shadow๋ฅผ Card ์ปดํฌ๋„ŒํŠธ๋กœ ๋”ฐ๋กœ ๋งŒ๋“ค์–ด๋ณด์ž. 
import "./Card.css";

function Card(props) {
  return <div className="card"></div>;
}

export default Card;
.card {
  border-radius: 12px;
  box-shadow: 0 1px 8px rgba(0, 0, 0.25);
}
import "./ExpenseItem.css";
import ExpenseDate from "./ExpenseDate";
import Card from "./Card";

function ExpenseItem(props) {
  return (
    <Card className="expense-item">
      <ExpenseDate date={props.date} />
      <div className="expense-item__description">
        <h2>{props.title}</h2>
        <div className="expense-item__price">${props.amount}</div>
      </div>
    </Card>
  );
}
export default ExpenseItem;
  • Card ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š๋Š”๋‹ค. 
  • we will use one special prop which is built into React, which every component receives, even if you're never setting it explicitly.
import "./Card.css";

function Card(props) {
  return <div className="card">{props.children}</div>;
}

export default Card;
  • Children, as I said, is a reserved name and the value of this special children prop will always be the content between the opening and closing tags of your custom component.
import "./Card.css";

function Card(props) {
  const classes = "card " + props.className;
  return <div className={classes}>{props.children}</div>;
}

export default Card;
  • now anything we receive as a class name from outside is added to that string.

Now, why would we do that? What did we gain by doing that?

๋ฆฌ์•กํŠธ๋กœ ์ž‘์—…ํ•  ๋•Œ  ํ•ญ์ƒ composition ์„ ์‚ฌ์šฉํ•˜๊ฒŒ ๋  ๊ฒƒ์ด๋‹ค. ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฒฐํ•ฉํ•  ๋•Œ๋งˆ๋‹ค, ์—ฌ๋Ÿฌ๋ถ„์€ composition์„ ์ด์šฉํ•œ๋‹ค. composition์—์„œ ํŠนํžˆ ์ค‘์š”ํ•œ ๋ถ€๋ถ„์€ props.children์ด๋‹ค. wrapper ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ํ•˜๋ฉฐ ํŠน๋ณ„ํ•œ ์ปดํฌ๋„ŒํŠธ์ด๋ฉฐ, ์ข…์ข… ์‚ฌ์šฉํ•  ์ผ์ด ์ƒ๊ธด๋‹ค. 

43. ์ฒซ ๋ฒˆ์งธ ์š”์•ฝ

  • component, jsx
  • how we organize our files
  • how we write our functions

44. JSX ์ž์„ธํžˆ ๋ณด๊ธฐ 

  • ๋ธŒ๋ผ์šฐ์ €๋Š” JSX ์ฝ”๋“œ๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๋Š”๋‹ค. 
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
  •  package.json ์—์„œ ๋ฆฌ์•กํŠธ์™€ ๊ด€๋ จ์žˆ๋Š” ๋‘ ๊ฐ€์ง€ ์ข…์† ์š”์†Œ๋ฅผ ๊ฐ–๊ณ  ์žˆ๋‹ค. 
  • ์—ฌ๊ธฐ ๋ถ€๋ถ„์€ ๊ฐ•์˜์— ๋‚˜์™€์žˆ๋Š” ๋ถ€๋ถ„์ด๋ž‘ ์‚ด์ง ๋‹ค๋ฅด๊ธด ํ•˜๋‹ค. version ์ด ๋‹ค๋ฅธ๊ฑด์ง€.. ๐Ÿ˜ถ๐Ÿ˜ถ
  • ๊ณผ๊ฑฐ ๋ฒ„์ „์—์„œ๋Š” ํ•ญ์ƒ react๋ฅผ import ํ•ด์•ผ ํ–ˆ๋‹ค. ์ตœ์‹  ๋ฒ„์ „์—์„œ๋Š” ํ•„์š”ํ•˜์ง€ ์•Š์Œ! 
  return React.createElement(
    "div",
    {},
    React.createElement("h2", {}, "Let's get started!"),
    React.createElement(Expenses, { itmes: expenses })
  );
  
   // return (
  //   <div>
  //     <h2>Let's get started!</h2>
  //     <div>
  //       <Expenses items={expenses} />
  //     </div>
  //   </div>
  // );
import React from "react";
  • ๊ธฐ์ˆ ์ ์œผ๋กœ ์œ„ ์ฝ”๋“œ๋ฅผ Import ํ•  ํ•„์š”๋Š” ์—†์ง€๋งŒ, JSX ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ๋ฆฌ์•กํŠธ๊ฐ€ ์‚ฌ์‹ค์€ ๋‚ด๋ถ€์—์„œ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ๊ฐ•์กฐํ•˜๊ธฐ ์œ„ํ•ด ํ•ด๋‹น ๊ตฌ๋ฌธ์„ import ํ•ด๋ณด์ž. 
  • ๋ฃจํŠธ jsx ์š”์†Œ๋กœ ์™œ ์ผ๋ถ€ wrapping ์š”์†Œ๊ฐ€ ํ•„์š”ํ•œ์ง€ ์•Œ ์ˆ˜ ์žˆ๋‹ค. (๋ฐ˜ํ™˜๋˜๋Š” ๋‘ ์š”์†Œ๋ฅผ ๋‚˜๋ž€ํžˆ ๊ฐ€์งˆ ์ˆ˜ ์—†๋Š” ์ด์œ ) ๋ฆฌ์•กํŠธ createElement ์„ธ๊ณ„์—์„œ๋Š” ํ•œ ๊ฐœ ์ด์ƒ์˜ children element ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” element 1๊ฐœ๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.  ๋”ฐ๋ผ์„œ ์ด ํ•œ๊ฐœ์˜ wrapper root jsx element๋ฅผ ๊ฐ–๋Š” ๊ฒƒ์ด๋‹ค. ํ•˜๋‚˜ ์ด์ƒ์„ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์—†๋‹ค. ์ด๋Š” ๋ณด์ด์ง€ ์•Š๋Š” ๊ณณ์—์„œ ์ผ์–ด๋‚˜๋Š” ์ž‘์—…๋“ค์ด๋‹ค. 

45. ์ปดํฌ๋„ŒํŠธ ํŒŒ์ผ ๊ตฌ์„ฑํ•˜๊ธฐ

  • components ํด๋” ์•ˆ์—์„œ๋„ ์ ์ ˆํ•˜๊ฒŒ ํด๋”๋ฅผ ๋‚˜๋ˆ ์„œ ํ™œ์šฉํ•˜๋Š” ๊ฒŒ ์ข‹๋‹ค.

46.  ๋Œ€์ฒด ํ•จ์ˆ˜ ๋ฌธ๋ฒ•(syntax)

  • arrow function ํ™œ์šฉํ•˜๊ธฐ 
  • ํ•˜์ง€๋งŒ ๊ฐœ์ธ์˜ ์ทจํ–ฅ์ด๋‹ˆ ์ทจํ–ฅ๊ป ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค. (just personal preference)
function App() {
	...
}

const App = () => { // arrow function 
	...
}

 


https://www.udemy.com/course/best-react/
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
https://www.codingfactory.net/12959

๋ฐ˜์‘ํ˜•