Search⌘ K
AI Features

Specifying a prop as optional

Explore how to create strongly-typed function component props in React using TypeScript. Learn to specify optional props with the correct syntax, render them conditionally, and use React Fragments for proper JSX structure. This lesson helps you make your components more flexible and easier to consume by specifying optional props correctly.

We'll cover the following...

It is possible to do this in TypeScript by putting a ? before the type annotation.

In our CodeSandbox project that we were working on in the last lesson, add an optional message prop to the Hello component. Render the value of the message prop on the line after the hello message in a ...