You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
551 B
33 lines
551 B
import React from "react";
|
|
import ReactDOM from "react-dom";
|
|
|
|
// 组件状态和事件
|
|
|
|
type State = { count: number }
|
|
class Counter extends React.Component<{}, State> {
|
|
state: State = {
|
|
count: 0
|
|
}
|
|
|
|
handleCLick = () => {
|
|
this.setState({
|
|
count: this.state.count + 1
|
|
})
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<div>
|
|
计数器: {this.state.count}
|
|
<button onClick={this.handleCLick}>+1</button>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
const App = () => <div>
|
|
<Counter/>
|
|
</div>
|
|
|
|
ReactDOM.render(<App />, document.getElementById('root'))
|