[Code Camp 1주차] Import & Export?

FE 08김우중·2022년 7월 6일
0

자바스크립트를 사용하면서 수없이 많이 본 import, export...
js파일 하나하나가 모듈이기때문에, 다른 곳에서 다른 모듈을 사용하기 위해서는 import와 export를 사용해야 하는데, 오늘은 import와 export에 대해 알아보자

Export?

Export = 내보내다
말 그대로 모듈을 내보내는 것이다.
모듈 하나를 다른 모듈에서도 이용할 수 있게 내보내는것이다

1. 하나만 내보내기

const test = () => {
	return (
    	<div>hello, react</div>
    )
}

export default test;

2. 여러개를 내보내기

export function computer() {
	console.log('hi');
}

export function mouse() {
	console.log('hello');
}

3. 여러개를 한번에 내보내기

function computer() {
	console.log('hi');
}

function mouse() {
	console.log('hello');
}

export { computer, mouse };

Import?

Import = 불러오다
export를 통해 내보낸 모듈을 불러오는것이다

import test from './test.js' 
import { computer, mouse } from './test.js'
profile
새내기 개발자

0개의 댓글