adspace


What is the difference between using constructor vs getInitialState in React?

Answer Posted / Rahil Saeed

In React, both the constructor and getInitialState methods are used to initialize a component's state. However, since version 16.0, getInitialState has been deprecated in favor of using the constructor method. The main difference is that constructor provides more flexibility as it accepts arguments (via super()), and allows you to bind 'this' to event handlers.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

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

564


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

448