Importing a Component | Create React App
This project setup supports ES6 modules thanks to webpack.
create-react-app.dev
프로젝트 가장 상위 폴더에 jsconfig.json 파일을 생성한다.
생성된 jsconfig.json 파일 안에 아래 코드를 넣어주면 끝!
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}
import Button from './Button';
상대 경로로 import하던 것을
import Button from 'components/Button';
이제 절대 경로로 import 가능하다.
import Button from 'src/components/Button';
와 같음
장점은 상대 경로를 사용할 때보다 깔끔해져서 보기 편하다는 것!
'react' 카테고리의 다른 글
[react] 제어 컴포넌트(Controlled Component)와 비제어 컴포넌트(UnControlled Component) (1) | 2023.01.02 |
---|---|
[react] github에서 API key값 숨기기(ex. firebase) (0) | 2022.12.30 |
[react] react에서 firebase 사용방법 (0) | 2022.12.29 |
[react] useScroll, useFullScreen (0) | 2022.12.14 |
[react] Hooks란? (0) | 2022.12.14 |