Home export์™€ export default์˜ ์ฐจ์ด
Post
์ทจ์†Œ

export์™€ export default์˜ ์ฐจ์ด

๐Ÿ”– export์™€ export default์˜ ์ฐจ์ด

๐Ÿ“Œ ๋ฐฐ์šด ๋‚ด์šฉ ๋ฐ ๊ธฐ์–ตํ•˜๊ณ  ์‹ถ์€ ๋‚ด์šฉ

export

  • ํ•ด๋‹น ๋ชจ๋“ˆ์—๋Š” ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๊ฐœ์ฒด๊ฐ€ ์žˆ์Œ
  • ์—ฌ๋Ÿฌ๊ฐœ์˜ ๊ฐœ์ฒด๋ฅผ ๋‚ด๋ณด๋‚ผ๋•Œ ์‚ฌ์šฉ
  • ํŠน์ • ๊ฐœ์ฒด๋งŒ ๋”ฐ๋กœ import ๊ฐ€๋Šฅํ•จ
  • ์ค‘๊ด„ํ˜ธ ํ•„์š”ํ•จ
  • ์›ํ•˜๋Š” ์ด๋ฆ„์œผ๋กœ import ๋ถˆ๊ฐ€๋Šฅ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Animals.js
function Duck() {
  return <h1>Hi! I'm Duck!</h1>;
}

function Goose() {
  return <h1>Hello! I'm Goose~!</h1>;
}

export Duck;
export Goose;


// AnimalsIntro.js
import { Duck } from "./Animals.js"

export default

  • ํ•ด๋‹น ๋ชจ๋“ˆ์—๋Š” ํ•˜๋‚˜์˜ ๊ฐœ์ฒด(๋ณ€์ˆ˜, ํด๋ž˜์Šค, ํ•จ์ˆ˜โ€ฆ)๋งŒ ์žˆ์Œ
  • ํ•˜๋‚˜์˜ ๊ฐœ์ฒด๋ฅผ ๋‚ด๋ณด๋‚ผ๋•Œ ์‚ฌ์šฉ
  • ์ค‘๊ด„ํ˜ธ ํ•„์š”์—†์Œ
  • ์›ํ•˜๋Š” ์ด๋ฆ„์œผ๋กœ import ๊ฐ€๋Šฅ
1
2
3
4
5
6
7
8
9
10
// Animal.js
function Duck() {
  return <h1>Hi! I'm Duck!</h1>;
}

export default Duck;


// AnimalIntro.jsx
import Duck from "./Animal.js" // import {default as Duck} from "./Animal"
This post is licensed under CC BY 4.0 by the author.

defaultProps๋กœ ๊ธฐ๋ณธ๊ฐ’ ์„ค์ •

useCallback์„ ์‚ฌ์šฉํ•˜์—ฌ ํ•จ์ˆ˜ ์žฌ์‚ฌ์šฉํ•˜๊ธฐ