Skip to content

Commit d5b7133

Browse files
Contribute an alternative typing example for forms sample
1 parent f424a81 commit d5b7133

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,32 @@ class App extends React.Component<{}, { // no props
369369
}
370370
```
371371

372+
You can also use React's event handler types like this:
373+
374+
```tsx
375+
class App extends React.Component<{}, { // no props
376+
text: string,
377+
}> {
378+
state = {
379+
text: ''
380+
}
381+
render() {
382+
return (
383+
<div>
384+
<input
385+
type="text"
386+
value={this.state.text}
387+
onChange={this.onChange}
388+
/>
389+
</div>
390+
);
391+
}
392+
onChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
393+
this.setState({text: e.currentTarget.value})
394+
}
395+
}
396+
```
397+
372398
[Something to add? File an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new).
373399

374400
# Section 3: Advanced Guides

0 commit comments

Comments
 (0)