N
N
Nikolai Antonov2016-08-18 01:00:35
JavaScript
Nikolai Antonov, 2016-08-18 01:00:35

What's the difference between extends Component and extends React.Component?

There are 2 ways to create components in React:
1) NewComponent extends Component {...}
1) NewComponent extends React.Component {...}
What's the difference? What pitfalls may be in the future?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2016-08-18
@my-nickname

Both options are the same, just in the 1st case we explicitly import Component from the react library and inherit from it:

import React, { Component } from 'react';
class App extends Component {}

import React from 'react';
class App extends React.Component {}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question