首页 > 解决方案 > React 16.7 - React.SFC 现在已弃用

问题描述

我用来声明这样的无状态组件:

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

然而,证监会现在已被弃用,也许Dan Abramov 的这篇推特帖子解释了原因。

现在 SFC 已被弃用,我们应该使用什么?

标签: reactjstypescriptdeprecateddeprecation-warning

解决方案


您应该使用React.FunctionComponent将 React 的 SFC 重命名为 'FunctionalComponent

此 PR 将React.SFC和重命名React.StatelessComponentReact.FunctionComponent,同时为旧名称引入了已弃用的别名。

所以你的例子会变成:

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

或者

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

推荐阅读