mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
28 lines
549 B
TypeScript
28 lines
549 B
TypeScript
import React from 'react';
|
|
import { Button } from './Button';
|
|
|
|
export class Counter extends React.Component<{ text: string }, { counter: number }> {
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {
|
|
counter: 0
|
|
};
|
|
}
|
|
render() {
|
|
const { counter } = this.state;
|
|
const { text } = this.props;
|
|
return (
|
|
<div>
|
|
{text}: {counter}
|
|
<Button
|
|
onClick={() => {
|
|
this.setState({ counter: counter + 1 });
|
|
}}
|
|
>
|
|
Click
|
|
</Button>
|
|
</div>
|
|
);
|
|
}
|
|
}
|