...

/

Specifying a type for function component props

Specifying a type for function component props

In this lesson, we will learn how to create strongly-typed props for function components.

One of the most beneficial parts of using TypeScript with React is the ability to have strongly-typed component props. This allows developers using the component to quickly understand what they can pass and helps them avoid making mistakes.

Specifying a type for function component props #

In this section, we will create a React Hello component that has a simple prop for who to say hello to. We will explore two different ways of strongly-typing the component props.

We are going to use CodeSandbox to explore this topic. So, let’s open the CodeSandbox project by clicking the following link:

CodeSandbox exercise

Can you spot a problem with the Hello component at the ...