Files
JavaScriptServices/templates/ReactSpa/ClientApp/components/Counter.tsx

31 lines
723 B
TypeScript

import * as React from 'react';
interface CounterState {
currentCount: number;
}
export class Counter extends React.Component<void, CounterState> {
constructor() {
super();
this.state = { currentCount: 0 };
}
public render() {
return <div>
<h1>Counter</h1>
<p>This is a simple example of a React component.</p>
<p>Current count: <strong>{ this.state.currentCount }</strong></p>
<button onClick={ () => { this.incrementCounter() } }>Increment</button>
</div>;
}
incrementCounter() {
this.setState({
currentCount: this.state.currentCount + 1
});
}
}