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



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

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

More React.js Interview Questions

What are refs in react and why are they important?

1 Answers  


Explain the components of Redux?

1 Answers  


Explain the significance of store in redux?

1 Answers  


How state is useful for react?

1 Answers  


what are the limitations of react?

1 Answers  


Can you explain about the standard javascript toolchain, transpilation, jsx?

1 Answers  


Name the different React lifecycle methods.

1 Answers  


What are state and props in reactjs? What is the difference between the two? Give a proper example of using state and props to elaborate the concept with complete source code?

1 Answers  


State the main difference between Pros and State?

1 Answers  


Explain step by step approach on how to setup environment for reactjs?

1 Answers  


What are the main features of react intl?

1 Answers  


How to pass a parameter to an event handler or callback?

1 Answers  


Categories