React.FC is a generic type alias in TypeScript used to define a function component in React. It stands for \"Function Component\" and is a shorthand for defining a function that returns JSX elements.
Using React.FC allows us to define our function component with props and their types in a more concise way. Here's an example:
import React from 'react';
interface Props {
name: string;
}
const MyComponent: React.FC<Props> = ({ name }) => {
return <div>Hello, {name}!</div>;
};
In the example above, we define a function component called MyComponent which takes in one prop called name. The prop type is defined using an interface called Props. We use React.FC<Props> to define the function component and to specify the prop types.
The advantage of using React.FC is that it provides better type checking and makes it easier to define the prop types of the component. Additionally, it also provides better support for defaultProps and propTypes.
It's important to note that if you are not using TypeScript, you don't need to use React.FC. You can simply define your function component as follows:
const MyComponent = ({ name }) => {
return <div>Hello, {name}!</div>;
};
In summary, React.FC is a generic type alias in TypeScript used to define function components in React. It provides better type checking and makes it easier to define prop types.