var Test = React.createClass({for ES6, we use constructor do same thing:
getInitialState: function(){
return {qty:1000};
},
render:function(){
return(
<p>{this.state.qty}</p>
);
}
})
React.render(<Test/>, document.getElementById("root"));
class Test extends React.Component {
constructor(props) {
super(props);
this.state = {qty: 1000};
// This line is important!
}
render() {
return (
<p>{this.state.qty}</p>
);
}
}
React.render(<Test/>, document.getElementById("root"));
Reference
https://reactjs.org/docs/react-without-es6.htmlhttps://stackoverflow.com/questions/30668326/what-is-the-difference-between-using-constructor-vs-getinitialstate-in-react-r
No comments :
Post a Comment