Import React 구문과 Import {Component } 구문의 차이
예를 들어 Respect with ES6를 사용하고 있습니다.React 및 컴포넌트는 다음과 같이 Import합니다.
import React from 'react'
import { Component } from 'react'
구문이 다른 이유는 무엇입니까?아래와 같이 사용할 수 없습니까?
import Component from 'react'
여기 의 자료가 있습니다.import.
import React from 'react'
위의 내용은 기본 Import입니다.기본 Import는 다음과 같이 내보냅니다.export default .... 디폴트 내보내기는 1개뿐입니다.
import { Component } from 'react'
단, 이것은 멤버 Import(이름 있는 Import)입니다.멤버 Import는 다음과 같이 내보냅니다.export .... 회원 수출은 여러 가지가 있을 수 있습니다.
다음 구문을 사용하여 둘 다 Import할 수 있습니다.
import React, { Component } from 'react';
JavaScript에서는 기본 Import와 명명된 Import가 분할되므로 기본값과 같이 명명된 Import를 가져올 수 없습니다.다음에, 이름을 설정합니다.Component디폴트 내보내기'react'package(패키지와는 동일하지 않음React.Component:
import Component from 'react';
컴포넌트는 이름 있는 내보내기입니다.따라서 {}을(를) 사용하여 비구조화해야 합니다.
React는 React에서 React를 내보내는 기본 내보내기입니다(예: export default React).
기본적으로 다음과 같은 문장으로 파일을 내보내는 경우export default React를 Import 할 수 있습니다.import React.
기본값이 아닌 다른 내보내기의 경우 다음과 같은 괄호 안에 Import할 항목을 지정해야 합니다.import { Components}.
언급URL : https://stackoverflow.com/questions/41768205/difference-between-import-react-and-import-component-syntax
'programing' 카테고리의 다른 글
| 타이프스크립트:사용자 지정 유형에 대해 "type of" 확인 (0) | 2023.03.25 |
|---|---|
| 서버 127.0.0.1 셸/mongo에 연결할 수 없습니다.js (0) | 2023.03.25 |
| Uncaughed TypeError: 정의되지 않은 속성(React-Router-Dom)을 읽을 수 없습니다. (0) | 2023.03.25 |
| "not null"과 "not null enable" 사이에는 차이가 있습니까? (0) | 2023.03.25 |
| JavaScript만으로 WordPress 플러그인을 만들 수 있습니까? (0) | 2023.03.25 |