Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typing return type of React components

This PR to Create-React-App removes React.FC as the return type for components (for the reasoning why, see the PR). Does this mean that ESlint's explicit function return type rule should no longer apply to React components? If so, how would one go about keeping ESlint happy?

like image 724
Jefferson Avatar asked Jul 25 '26 06:07

Jefferson


1 Answers

You can use React.ReactElement | null as the return type of your function components. That's what React.FC does today.

interface Props {
  children: React.ReactNode;
}

const MyComponent = ({ children }: Props): React.ReactElement => (
  <div>{children}</div>
)
like image 93
Karol Majewski Avatar answered Jul 28 '26 16:07

Karol Majewski