JavaScript에서 타 파일의 내용을 참조해야하는 경우 import/export 문법을 사용한다.
Import
- 타 파일에서 export된 항목에 대해 접근할 수 있도록 한다.
Export
- 타 파일에서 import 할 수 있도록 접근 가능한 대상을 지정한다.
// export 예제
let data = [
{
id : 0,
title : "White and Black",
content : "Born in France",
price : 120000
},
{
id : 1,
title : "Red Knit",
content : "Born in Seoul",
price : 110000
},
{
id : 2,
title : "Grey Yordan",
content : "Born in the States",
price : 130000
}
];
export default data;
// import 예제
import data from './data.js';
let [goods] = useState(data);
'개발 > React 학습' 카테고리의 다른 글
Nested Routes (0) | 2023.03.15 |
---|---|
React Router (0) | 2023.03.15 |
외부 리소스 참조하기 (0) | 2023.03.08 |
React Bootstrap 사용 (0) | 2023.03.08 |
Class component (0) | 2023.03.07 |