자바스크립트를 사용하면서 수없이 많이 본 import, export...
js파일 하나하나가 모듈이기때문에, 다른 곳에서 다른 모듈을 사용하기 위해서는 import와 export를 사용해야 하는데, 오늘은 import와 export에 대해 알아보자
Export?
Export = 내보내다
말 그대로 모듈을 내보내는 것이다.
모듈 하나를 다른 모듈에서도 이용할 수 있게 내보내는것이다
const test = () => {
return (
<div>hello, react</div>
)
}
export default test;
export function computer() {
console.log('hi');
}
export function mouse() {
console.log('hello');
}
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'