💪State và Prop trong React
State và Prop trong React: Khác biệt và Mối quan hệ
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = { count: 0 };
}
incrementCount = () => {
this.setState({ count: this.state.count + 1 });
};
render() {
return (
<div>
<h1>Count: {this.state.count}</h1>
<button onClick={this.incrementCount}>Increment</button>
</div>
);
}
}Đặc điểm
State
Prop
PreviousLý do team React gộp 3 lifecycle vào useEffectNextHàm setState trong React là hàm bất đồng bộ.
Last updated