React学习案例二十四

class LoggingButton extends React.Component {
// 这个语法确保了 `this` 绑定在 handleClick
// 这里只是一个测试
handleClick = () => {
console.log('this is:', this);
}

render() {
return (
<button onClick={this.handleClick}>
Click me
</button>
);
}
}




<!-- class LoggingButton extends React.Component {
// 这个语法确保了 `this` 绑定在 handleClick
// 这里只是一个测试
handleClick = () => {
console.log('this is:', this);
}

render() {
return (
<button onClick={this.handleClick}>
Click me
</button>
);
}
} -->


<!-- class LoggingButton extends React.Component {
// 这个语法确保了 `this` 绑定在 handleClick
// 这里只是一个测试
handleClick = () => {
console.log('this is:', this);
}

render() {
return (
<button onClick={this.handleClick}>
Click me
</button>
);
}
} -->


<!-- class LoggingButton extends React.Component {
// 这个语法确保了 `this` 绑定在 handleClick
// 这里只是一个测试
handleClick = () => {
console.log('this is:', this);
}

render() {
return (
<button onClick={this.handleClick}>
Click me
</button>
);
}
} -->



<!-- class LoggingButton extends React.Component {
// 这个语法确保了 `this` 绑定在 handleClick
// 这里只是一个测试
handleClick = () => {
console.log('this is:', this);
}

render() {
return (
<button onClick={this.handleClick}>
Click me
</button>
);
}
} -->



<!-- class LoggingButton extends React.Component {
// 这个语法确保了 `this` 绑定在 handleClick
// 这里只是一个测试
handleClick = () => {
console.log('this is:', this);
}

render() {
return (
<button onClick={this.handleClick}>
Click me
</button>
);
}
} -->