What is the difference between React.FunctionComponent and React.SFC. I'm new To typescript, and actually I don't know when to use one over the other. for example when using react hooks should I use only React.FunctionComponent, because I use some sort of state inside my component.
2 Answers
React.SFC (which stands for stateless function component) is an alias for React.FunctionComponent.
It was deprecated because functional components aren't stateless since React 16.8.
Comments
They are the same, just one a newer terminology. Have a look at the definitions, they are both aliases for the same definition:
type SFC<P = {}> = FunctionComponent<P>;
type FC<P = {}> = FunctionComponent<P>;
1 Comment
Abdellah El Mennani
yes that's correct, I looked to the code source and they mentioned that React.SFC is deprecated because of The new React Hooks:
/** * @deprecated as of recent React versions, function components can no * longer be considered 'stateless'. Please use `FunctionComponent` instead. * * @see [React Hooks](https://reactjs.org/docs/hooks-intro.html) */ type SFC<P = {}> = FunctionComponent<P>;