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

Answer

The two approaches are not interchangeable. You should initialize state in the constructor when using ES6 classes, and define the getInitialState method when using React.createClass.

class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = { /* initial state */ };
}
}
is equivalent to

var MyComponent = React.createClass({
getInitialState() {
return { /* initial state */ };
},
});

All REACT NATIVE Questions

Ask your interview questions on react-native

Write Your comment or Questions if you want the answers on react-native from react-native Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---