React 16.7 - React.SFC is now deprecated

南笙酒味 提交于 2019-12-18 13:52:42

问题


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 Abramov explains why.

What should we use now that SFC is deprecated?


回答1:


You should use 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.

So your example would become:

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

or

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


来源:https://stackoverflow.com/questions/53885993/react-16-7-react-sfc-is-now-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!