简体   繁体   English

何时在 React 中使用基于类的组件

[英]When to use class-based component in React

在 React 16.8 中引入React Hooks以及在功能组件中控制组件状态和生命周期方法的所有新方法(例如useStateuseEffect ,功能组件和基于类的组件之间的剩余区别不再明显,因此真正的区别是什么?

There are some lifecycle methods, which can't be emulated with React Hooks(egcomponentDidCatch() ).有一些生命周期方法不能用 React Hooks 模拟(例如componentDidCatch() )。

In this cases you still need class components, but overall, you don't need them, and it's already totally fine, if you have an app without them.在这种情况下,您仍然需要类组件,但总的来说,您不需要它们,如果您的应用程序没有它们,那已经完全没问题了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将基于 React 类的组件转换为函数式组件? - How to convert a React class-based component into a functional component? 将基于反应类的组件转换为基于功能的组件 - convert react class-based to functional based component 在 React 中将外部库从基于类迁移到函数式组件 - Moving external library from Class-based to Functional Component in React 如何将基于类的组件中的函数转换为 React 中的函数式组件? - How can I convert functions in class-based component to functional components in React? 基于类的vue组件如何加载动态组件 - How load dynamic component in class-based vue component 将数据传递给 React(本机)钩子,如基于类的组件 - Pass data to React (Native) hooks like class-based components 当您从基于类的 React 组件切换到基于函数的 React 组件时,公共方法的替代方法是什么? - What's the alternative to public methods when you switch from class-based to function-based React components? 基于 class 的 React 组件使用什么类型? - What type to use for a class based React component? 为什么使用无状态功能组件而不是基于类的组件? - Why use stateless functional Components instead of class-based Components? 从子组件向父组件发出事件在 Vue.js 中不起作用(使用基于类的装饰器) - Emitting event from child to parent component not working in Vue.js (using class-based decorator)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM