Skip to content

Commit d20f5f2

Browse files
authored
Update forms-and-events.md
Alternative to event handler
1 parent 9e7fdb5 commit d20f5f2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/basic/getting-started/forms-and-events.md

+13
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ class App extends React.Component<Props, State> {
4040
}
4141
```
4242

43+
An alternative to the event handler would also work:
44+
45+
```tsx
46+
import { ChangeEvent} from 'react'
47+
48+
49+
const handleChance = (e: ChangeEvent<HTMLInputElement>) => {
50+
console.log(e.target.name)
51+
console.log(e.target.value)
52+
}
53+
54+
```
55+
4356
[View in the TypeScript Playground](https://www.typescriptlang.org/play/?jsx=2#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wFgAoCtAGxQGc64BBMMOJADxiQDsATRsnQwAdAGFckHrxgAeCnDgBvAL4AaBcs2KA9Drg8IcMDjB1tcblwBccOjCjAeAcwDcmlRQB8W8ovso3HAAvL6KilYwtgBE0R7ulH5wepYAnmBOznAQPIgAkgDiABIAKnAAFij8dsB8SNmYIZo5YpUu9aEAFEi2QhgiAGLQIACiAG4ysqUAsgAyeTxgAK4wI9RIIDJeAJS2YxC1IT5KFjDlwHQidEgwAMowgUidSpacUewiaEtQRDwwJSgoM4biIxihqEt6iptglFCpYXBfnUoJ1tmFwkQYN9cp0LIpZHxgGMvHjwrInMt4DB0khgtFItE4GCIbSlGcLlcHtwRJEVNkeK0qsDgmzzpcWm1gXydCSkuE4LIdITiRYYR4KCogA)
4457

4558
Instead of typing the arguments and return values with `React.FormEvent<>` and `void`, you may alternatively apply types to the event handler itself (_contributed by @TomasHubelbauer_):

0 commit comments

Comments
 (0)