React Utility Types

Last updated

@types/react comes with a few convenient utility types that I didn’t learn about until way too late.

Seb ⚛️ avatar
Seb ⚛️ @sebastienlorber
React + TypeScript tip No need to import DOM event handler types This always works and is easy to remember
Tweet media

This is like the Parameters<F> utility type to extract the type of a components props.

Get the right mouse for a specific HTML element

type ButtonProps = React.MouseEventHandler<HTMLButtonElement>

Just adds { children: ReactNode } to the given type.