CS-Notes/docs/_style/prism-master/examples/prism-tsx.html

32 lines
574 B
HTML
Raw Normal View History

2018-12-19 14:09:39 +08:00
<h2>Full example</h2>
<pre><code>import * as React from 'react';
interface IState {
clicks: number;
}
export class Clicker extends React.Component&lt;any, IState> {
constructor(props) {
super(props);
this.state = {
clicks: 0,
};
}
public clickHandler = () => {
this.setState({ clicks: this.state.clicks + 1 });
}
public render() {
return (
&lt;div>
&lt;p>You have clicked the button {this.state.clicks} time(s).&lt;/p>
&lt;p>
&lt;button onClick={this.clickHandler}>click me&lt;/button>
&lt;/p>
&lt;/div>
);
}
}</code></pre>