Implication of super(props) in react

Mugund K
2 min readDec 7, 2018

--

“super” keyword in JavaScript refers to the parent class constructor. Lets take the following sample react component,

Minimalist react component with super

And this how it appears in react dev console.

How its rendered in react-dev-tools

As we mentioned earlier , “super” keyword refers to parent class constructor — Then its obvious our example react component points to the ‘React.Component’ implementation.

Game on. Lets remove ‘super(props)’ keyword from our react component and see how it looks in debugger console. Doing so we were greeted with this error at console.

When super(props) is commented out !

Looking at the error its obvious that we are not allowed to use “this” unless you called the parent constructor . So bottom line is you need to run parent constructor before your actions with“this” at child constructor. This enforcement is comes from JavaScript and no other go, we need to adapt with it.

--

--