Return to site
REACT ⚛️: If you want to import just the Component from the React library, what syntax do you use?
REACT ⚛️: If you want to import just the Component from the React library, what syntax do you use?
·
Choose ONE below:
- import React.Component from 'react'
- import [ Component ] from 'react'
- import Component from 'react'
- import { Component } from 'react'
Answer:
If you want to import just the Component class from the React library, you would use the following syntax in your JavaScript file:
import React, { Component } from 'react';
This syntax uses destructuring assignment to import the Component class specifically from the react module, which is the main package for the React library. You can then use the Component class to create your own components.
Alternatively, you can also import just the Component class as follows:
import { Component } from 'react';