reactjs - React 16.7 - React.SFC 现在已弃用
问题描述
我用来声明这样的无状态组件:
const example: React.SFC<IExample> = ({propsType}) => ();
然而,证监会现在已被弃用,也许Dan Abramov 的这篇推特帖子解释了原因。
现在 SFC 已被弃用,我们应该使用什么?
解决方案
您应该使用React.FunctionComponent
:将 React 的 SFC 重命名为 'FunctionalComponent
此 PR 将
React.SFC
和重命名React.StatelessComponent
为React.FunctionComponent
,同时为旧名称引入了已弃用的别名。
所以你的例子会变成:
const example: React.FunctionComponent<IExample> = ({propsType}) => ();
或者
const example: React.FC<IExample> = ({propsType}) => ();
推荐阅读
- chart.js - Chart.js“minBarLength”没有按预期工作?
- cmake - 运行连接器 C++ 程序时出现疯狂错误
- java - Hibernate 在一对多映射中更新子条目
- sql - 尝试将个人表加入到夫妻表中,提供家庭 ID,而不是让服务器超时
- apache-kafka - Kafka Broker 领导者变更无效
- flutter - Flutter Camera 插件(自动缩放)
- javascript - 删除数据 Javascript
- c - 如何从内核空间中的用户空间指针中正确提取字符串?
- bixby - 如何在 Input-View 中访问 Bixby 个人资料信息(名字/姓氏)
- r - 使用 lapply 读取时动态删除文件