What is the correct type for React events. Initially I just used any
for the sake of simplicity. Now, I am trying to clean things up and avoid use of any<
I have the following in a types.ts
file for html input, select, and textarea:
export type InputChangeEventHandler = React.ChangeEventHandler
export type TextareaChangeEventHandler = React.ChangeEventHandler
export type SelectChangeEventHandler = React.ChangeEventHandler
Then import them:
import { InputChangeEventHandler } from '../types'
Then use them:
const updateName: InputChangeEventHandler = (event) => {
// Do something with `event.currentTarget.value`
}
const updateBio: TextareaChangeEventHandler = (event) => {
// Do something with `event.currentTarget.value`
}
const updateSize: SelectChangeEventHandler = (event) => {
// Do something with `event.currentTarget.value`
}
Then apply the functions on your markup (replacing ...
with other necessary props):