Skip to content

Latest commit

ย 

History

History
67 lines (52 loc) ยท 1.52 KB

File metadata and controls

67 lines (52 loc) ยท 1.52 KB

prop-types

element vs elementType

element

// ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ
export const Container = () => {
  return (
    <div>
      <Content element={<Element />} />
    </div>
  )
};

---

// ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ
export const Content = ({ element }) => {
  return (
    <div>
      {element}
    </div>
  )
}

elementType

// ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ
export const Container = () => {
  return (
    <div>
      <Content Element={Element} />
    </div>
  )
};

---

// ํ•˜์œ„ ์ปดํฌ๋„ŒํŠธ
export const Content = ({ Element }) => {
  return (
    <div>
      <Element />
    </div>
  )
}

prop-types์™€ Typescript

  • ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ๋Š” ๋‘˜ ๋‹ค ์‚ฌ์šฉํ–ˆ์„ ๋•Œ, ํฐ ์ด์ ์„ ๊ฐ€์ง€์ง€ ๋ชปํ•œ๋‹ค.
  • ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋Š” ์ปดํŒŒ์ผ ํƒ€์ž„์— ํƒ€์ž…์„ ๊ฒ€์‚ฌํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ์‚ฌ์šฉ์ž์˜ ๋™์ ์ธ ์ž…๋ ฅ์— ๋”ฐ๋ฅธ ์˜ค๋ฅ˜๋ฅผ ๊ฒ€์‚ฌํ•˜์ง€ ๋ชปํ•œ๋‹ค.
  • prop-types๋Š” ๋™์ ์œผ๋กœ ํƒ€์ž…์„ ๊ฒ€์‚ฌํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ์‚ฌ์šฉ์ž๊ฐ€ ์ง€์ •๋œ ํƒ€์ž…์— ๋งž์ง€ ์•Š๋Š” ์ž…๋ ฅ์„ ํ•˜๋Š” ๊ฒฝ์šฐ๋„ ๊ฒ€์‚ฌํ•  ์ˆ˜ ์žˆ๋‹ค.
  • [์ฐธ๊ณ ] PropTypes in a TypeScript React Application - stack overflow

์ฐธ๊ณ 


[TOP] | [HOME]