React 16.7-现在不推荐使用React.SFC [英] React 16.7 - React.SFC is now deprecated

查看:1259
本文介绍了React 16.7-现在不推荐使用React.SFC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use to declare stateless components like this:

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

但是现在不推荐使用SFC,也许这篇来自Dan Abramov的推特帖子解释了原因。

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

SFC已过时,我们应该使用什么?

What should we use now that SFC is deprecated?

推荐答案

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


此PR将 React.SFC React.StatelessComponent 重命名为 React.FunctionComponent ,同时为旧名称引入了不建议使用的别名。

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

因此您的示例将变为:

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

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

这篇关于React 16.7-现在不推荐使用React.SFC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆