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
React 16.7 - React.SFC is now deprecated
提问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.SFC
andReact.StatelessComponent
toReact.FunctionComponent
, while introducing deprecated aliases for the old names.
此 PR 将
React.SFC
和重命名React.StatelessComponent
为React.FunctionComponent
,同时为旧名称引入已弃用的别名。
So your example would become:
所以你的例子会变成:
const example: React.FunctionComponent<IExample> = ({propsType}) => ();
or
或者
const example: React.FC<IExample> = ({propsType}) => ();