at the top of my Create React App created file App.js is the line import React, { Component } from 'react';
Won't React import everything already... and if yes then why is { Component } needed?
at the top of my Create React App created file App.js is the line import React, { Component } from 'react';
Won't React import everything already... and if yes then why is { Component } needed?
On
It's just a short cut, so that you can write
class MyClass extends Component
Otherwise you'll have to prefix it.
On
If you don't use webpack and the Tree Shaking feature then It's just syntax sugar
Many people think this
class MyComponent extends Component
is more beautiul than
class MyComponent extends React.Component
But if you're using webpack with tree shaking then webpack will execute dead code elimination in your code
See more:
Importing
Componentseparately allows you to useComponentrather thanReact.Component. It's a convenience.