reactjs - React 16.7 - React.SFC 现已弃用

标签 reactjs typescript deprecated deprecation-warning

我像这样声明无状态组件:

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

然而证监会现在已被弃用,也许this twitter post from Dan Abramov解释原因。

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

最佳答案

你应该使用React.FunctionComponent:Rename React's SFC to 'FunctionalComponent

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}) => ();

关于reactjs - React 16.7 - React.SFC 现已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53885993/

相关文章:

javascript - react 路由器使用参数返回空对象

node.js - Angular2嵌套路由不起作用,没有报告错误,但空白页

java - 错误 : "The method show() from the type Window is deprecated"

c++ - 如何为已弃用的英特尔 IPP API 找到替代 API?

javascript - 简单的 Ajax 请求,在 React.js 中循环数据

python - 如何在不知道高度的情况下使用 python selenium 向下滚动?

javascript - 单独处理多个组件

angular - 无法将新方法添加到 Angular TypeScript 类 (FormGroup)

reactjs - TypeError : fs. existsSync 不是函数(Electron/ReactJS/Typescript)

java - 在 Java 1.6 中弃用