Categories
TypeScript Answers

How to fix the ‘React.SFC is now deprecated’ warning with React and TypeScript?

Spread the love

Sometimes, we want to fix the ‘React.SFC is now deprecated’ warning with React and TypeScript.

In this article, we’ll look at how to fix the ‘React.SFC is now deprecated’ warning with React and TypeScript.

How to fix the ‘React.SFC is now deprecated’ warning with React and TypeScript?

To fix the ‘React.SFC is now deprecated’ warning with React and TypeScript, we should replace with React.FunctionComponent or React.FC.

For instance, we write

const Example: React.FunctionComponent<IExample> = ({ propsType }) => {
  //...
};

to create the Example component of type React.FunctionComponent<IExample> where IExample is an interface with the props’ types.

We can shorten that to

const Example: React.FC<IExample> = ({ propsType }) => {
  //...
};

Conclusion

To fix the ‘React.SFC is now deprecated’ warning with React and TypeScript, we should replace with React.FunctionComponent or React.FC.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *