As the name suggests, a function component is implemented using a JavaScript function. These components are sometimes referred to as functional stateless components, which can be a little confusing because they can contain states in more recent versions of React.
Creating a function component
Creating a basic function component
Let's refactor our Confirm component to be a function component, in order to learn how to implement these:
- Open Confirm.tsx and replace the class signature with the following:
const Confirm: React.SFC<IProps> = (props) => {
...
}
We define a function component using an arrow function, passing the props type in as a generic parameter.
We'll learn about generic functions later in the...