When should I use JSX.Element or React.FC?

It is a good practice to use the appropriate type for your JSX elements and function components

Roberto Silva Zuñiga
2 min readJan 3, 2023
Photo by Nangialai Stoman on Unsplash

JSX.Element is the data type used to render JSX elements at runtime. On the other hand, React.FC is a data type that is used to represent a React component function. If you’re writing a React component and want to use the correct data type for your properties and your component itself, you should use React.FC. Here is an example of using both types:

JSX.Element

React.FC

JSX.Element and React.FC are data types that are used in different contexts in React. Although both data types can be used to define React components that use properties, there are some important differences between them.

The main difference is that JSX.Element is used to render JSX elements at runtime, while React.FC is used to render a React component function. A JSX element is simply a coded representation of a DOM element, while a React component function is a function that returns a JSX element.

Another important difference is that when using React.FC, you can specify the type of properties that a component accepts by using an interface. This can help ensure that the correct properties are being passed to the component, and can make your code easier to understand and maintain.

Soooo what does that mean? 🤯

👉 JSX.Element works when you want to create a component without props.

👉React.FC works when you want to pass props with definitions of the interface.

…and yes! you can combine them 🤝

There are some differences in the performance? 🤔

Using the proper type for a JSX element or a function component can help with code clarity and maintainability, but it will not have any effect on performance.

Using JSX.Element or React.FC to specify the types of your JSX elements and function components is not directly related to performance. However, having clear and well-defined types can make it easier to reason about your code, which can make it easier to spot potential performance issues.

It is generally a good practice to use the appropriate type for your JSX elements and function components, but whether you choose to use JSX.Element or React.FC will depend on the needs of your specific application.

Let me know if you liked it…😉 and don’t forget to give me lots of claps 😁

--

--

Roberto Silva Zuñiga

Solutions Architect / Software Engineer 🐈‍⬛ I’m a passionate for the technology and the new ideas in order to make easier our lives 🤖