React 16.7-React. SFC 现在不支持

我用来声明如下无状态组件:

const example: React.SFC<IExample> = ({propsType}) => ();

然而,证监会如今已不再受到重视,或许 Dan Abramov 的推特帖子能够解释其中的原因。

现在证监会已不再受欢迎,我们应该使用什么?

48583 次浏览

You should use React.FunctionComponent: Rename React's SFC to 'FunctionalComponent

This PR renames React.SFC and React.StatelessComponent to React.FunctionComponent, while introducing deprecated aliases for the old names.

So your example would become:

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

or

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

I'd say the accepted answer isn't up-to-date any more.

React.FunctionComponent has certain drawbacks, as explained by the folks at create-react-app. Their reasoning is pretty convincing, and I stopped using FC entirely.

Better alternative:

const example = ({ propsType }: IExample): JSX.Element => ();