typescript React 16.7 - React.SFC 现在已弃用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53885993/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:01:00  来源:igfitidea点击:

React 16.7 - React.SFC is now deprecated

reactjstypescriptdeprecateddeprecation-warning

提问by Jonas Praem

I use to declare stateless components like this:

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

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

However the SFC is now deprecated, maybe this twitter post from Dan Abramovexplains why.

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

What should we use now that SFC is deprecated?

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

回答by Do?ancan Arabac?

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

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

This PR renames React.SFCand React.StatelessComponentto React.FunctionComponent, while introducing deprecated aliases for the old names.

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

So your example would become:

所以你的例子会变成:

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

or

或者

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