Patricio Vargas
Patricio Vargas

Reputation: 5522

extends React.Component vs extends Component

I'm new to react and I have seen people using

class X extends Component {}

and

class X extends React.Component {}

When to use one or the other?

Upvotes: 0

Views: 128

Answers (1)

MinimalistYing
MinimalistYing

Reputation: 356

Both way is fine.The difference is depend on how you import Componet.

import React, { Component } from 'react'
class X extends Component {}

or

import React from 'react'
class X extends React.Component {}

Personally, I prefer the first way.

Upvotes: 2

Related Questions