Difference between constructor and getInitialState ?



Difference between constructor and getInitialState ?..

Answer / 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

More React.js Interview Questions

What are the controlled components and uncontrolled components in reactjs?

1 Answers  


What is ReactDOM and what is the difference between ReactDOM and React?

1 Answers  


What is the difference between state and props in react js?

1 Answers  


How can you embed two or more components into one?

1 Answers  


What is the component lifecycle in reactjs?

1 Answers  


Which is best react or angular?

1 Answers  


What are the lifecycle methods of reactjs components?

1 Answers  


What is the life cycle of reactjs components?

1 Answers  


What are lifecycle hooks react?

1 Answers  


What are refs in reactjs?

1 Answers  


What is ComponentWillMount()?

1 Answers  


How events are different in react?

1 Answers  


Categories