1

In JavaScript, we are not allowed to use variables and we can only define methods. Also if we want to initialise a variable, we should do it either in the constructor or the prototype of the class.But in ReactJs we can initialise state outside constructor.

Is ReactJs classes like class A extends React.Component{} different from normal javascript classes?

3
  • 1
    It is class properties syntax, supported by babel and is an ES7 syntax. You can refer stackoverflow.com/questions/45048879/… Commented Dec 26, 2018 at 11:08
  • This article React.createClass vs. ES6 Class Components gives a really good explanation on the history as well as the differences of the two classes.Thought of extracting a few paragraphs from this article and posting it as an answer but I think a complete read of the article would be better instead. Commented Dec 26, 2018 at 11:09
  • 1
    @ShubhamKhatri Except that it didn't make it into ES7, it's still a proposal only :-) Commented Dec 26, 2018 at 11:16

1 Answer 1

-1

You can refer Class variables in React with ES6

JS by default does not support declaring variables inside class. In case of React, it uses Babel transpiler which supports that syntax.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.