React Class components vs Functional components

别来无恙 提交于 2021-02-16 18:54:07

问题


Before React16, class components were used over functional components whenever there is a need to use state or lifecycle methods in your component. In the latest release react introduced Hooks and Effects using which we can use state and lifecycle methods inside our functional components.

So is there any reason why still the class components exists? Is there any cases we still have to choose class components over functional


回答1:


Here you can see the cases where you will need class components

The most common case where you will need class components is if you want to make an ErrorBoundary, you will need a class component because you can't implement componentDidCatch with hooks... yet!



来源:https://stackoverflow.com/questions/56260982/react-class-components-vs-functional-components

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