- Serverless Web Applications with React and Firebase
- Harmeet Singh Mayur Tanna
- 105字
- 2021-08-27 19:11:08
The constructor() method
The constructor method of React Component gets invoked first when the component is mounted. Here, we can set the state of the component.
Here's an example of constructor in React.Component:
constructor(props) {
super(props);
this.state = {
value: props.initialValue
};
}
Using this.props inside the constructor, we need to call super(props) to access and call functions of parents; otherwise, you will get this.props undefined in the constructor because React sets the .props on the instance from outside immediately after calling constructor, but it will not affect when you are using this.props inside the render method.
推薦閱讀
- Mastering Ext JS(Second Edition)
- 零基礎(chǔ)搭建量化投資系統(tǒng):以Python為工具
- Rust實(shí)戰(zhàn)
- JIRA 7 Administration Cookbook(Second Edition)
- Internet of Things with Intel Galileo
- PhpStorm Cookbook
- C語言程序設(shè)計(jì)同步訓(xùn)練與上機(jī)指導(dǎo)(第三版)
- Getting Started with Eclipse Juno
- Java網(wǎng)絡(luò)編程實(shí)戰(zhàn)
- Django實(shí)戰(zhàn):Python Web典型模塊與項(xiàng)目開發(fā)
- Illustrator CC平面設(shè)計(jì)實(shí)戰(zhàn)從入門到精通(視頻自學(xué)全彩版)
- SQL Server on Linux
- Java從入門到精通(視頻實(shí)戰(zhàn)版)
- Monitoring Docker
- Flink入門與實(shí)戰(zhàn)