React 渲染与生命周期方法详解
1. React 组件的渲染与生命周期方法概述
在 React 中,组件的渲染和生命周期方法是非常重要的概念。以下是一个父组件的示例代码:
console.log('ParentComponent: state');
this.state = { text: '' };
this.onInputChange = this.onInputChange.bind(this);
componentWillMount() {
console.log('ParentComponent: componentWillMount');
}
componentDidMount() {
console.log('ParentComponent: componentDidMount');
}
onInputChange(e) {
const text = e.target.value;
this.setState(() => ({ text: text }));
}
render() {
console.log('ParentComponent: render');
return [
<h2 key="h2">Learn about rendering and lifecycle methods!</h2>,
<input key="input" value=
超级会员免费看
订阅专栏 解锁全文
715

被折叠的 条评论
为什么被折叠?



