Import React
vs Import React, { Component }
Which one is better and why?
Or does it make no difference other than writing less cod
What these are are named imports or namespace imports. What they do is basically copy over the module's contents into the namespace allowing:
import React, { Component } from 'react';
class SomeComponent extends Component { ... }
Normally, we'd extend React.Component
, but since the Component module is imported into the namespace, we can just reference it with Component
, React.
is not needed. All React modules are imported, but the modules inside the curly brackets are imported in such a way that the React
namespace prefix is not needed when accessing.