DEV Community

Cover image for Creating a React Input component in Typescript

Creating a React Input component in Typescript

giselamd profile image Gisela Miranda Difini ・1 min read

Here is a nice way to create a React Input component using typescript!

Using an interface to declare your own prop types as well as extending all HTMLInputElement ( properties to allow your component to accept all those input props you might need to increase accessibility for example 😄

Here you can see that by extending those HTMLInputElement properties in InputProps we can have all input element props passed to this component. Instead of having to declare each one we can just use a spread attribute

Input component auto complete

React input component with spread attribute

Original post:

Discussion (2)

Editor guide
andrewbaisden profile image
Andrew Baisden

Good article I really should start working with Typescript.

leomjaques profile image
Leonardo J. 👨🏻‍💻

Nice one! Thanks for posting it :)