adspace


Difference between constructor and getInitialState ?

Answer Posted / Abhilash Pandey

In React, `constructor` is used for initializing state variables using the `super(props)` call and binding event handlers. On the other hand, `getInitialState()` function was deprecated in ES6 class components as it has been replaced by the `state` object. The constructor is necessary to bind methods to the component instance.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How would you create higher order components (hocs) in react.js?

448


How to use events in reactjs? Give an example of using events?

564