0

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?

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.