React 16.7有了State Hook,所以我在任何情况下都可以使用函数组件而不是类组件,对吗? https://reactjs.org/docs/hooks-state.html
最佳答案
实际上,使用 hook 时有一些规则:不要在循环、条件或嵌套函数内调用 Hook,也不要从常规 JavaScript 函数中调用 Hook。
您可以在此处阅读这些规则和说明:https://reactjs.org/docs/hooks-rules.html
这是官方的解释。
Our goal is for Hooks to cover all use cases for classes as soon as possible. There are no Hook equivalents to the uncommon getSnapshotBeforeUpdate and componentDidCatch lifecycles yet, but we plan to add them soon. It is a very early time for Hooks, so some integrations like DevTools support or Flow/TypeScript typings may not be ready yet. Some third-party libraries might also not be compatible with Hooks at the moment.
关于javascript - React 16.7有State Hook,我可以在任何情况下使用功能组件而不是类组件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53138465/