<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script crossorigin src="https://cdn.bootcdn.net/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<script crossorigin src="https://cdn.bootcdn.net/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>
<script crossorigin src="https://cdn.bootcss.com/babel-standalone/6.26.0/babel.js"></script>
<title>Document</title>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class Mycomponent extends React.Component{
constructor(props){
super(props);
this.state={isHot:true};
this.handleClick=this.handleClick.bind(this);
}
handleClick(){
this.setState(state=>({
isHot:!state.isHot
}))
}
render(){
console.log(this);
return <h1 onClick={this.handleClick}>今天天气很{this.state.isHot ? '炎热':'寒冷'}</h1>
}
}
ReactDOM.render(<Mycomponent />,document.getElementById('root'))
</script>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script crossorigin src="https://cdn.bootcdn.net/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<script crossorigin src="https://cdn.bootcdn.net/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>
<script crossorigin src="https://cdn.bootcss.com/babel-standalone/6.26.0/babel.js"></script>
<title>Document</title>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class Mycomponent extends React.Component{
state={isHot:true};
handleClick= ()=>{
this.setState(state=>({
isHot:!state.isHot
}))
}
render(){
return <h1 onClick={this.handleClick}>今天天气很{this.state.isHot ? '炎热':'寒冷'}</h1>
}
}
ReactDOM.render(<Mycomponent />,document.getElementById('root'))
</script>
</body>
</html>