getSnapshotBeforeUpdate 使用反应钩子 [英] getSnapshotBeforeUpdate using react hooks
问题描述
如何使用 React 钩子实现 getSnapshotBeforeUpdate 给我的相同逻辑?
How can I implement the same logic that getSnapshotBeforeUpdate gives me using react hooks?
推荐答案
根据 React Hooks FAQ,没有办法用钩子实现 getSnapshotBeforeUpdate
和 ComponentDidCatch
生命周期方法还
As per the React Hooks FAQ, there isn't a way to implement getSnapshotBeforeUpdate
and ComponentDidCatch
lifecycle method with hooks yet
Hook 是否涵盖类的所有用例?
我们的目标是让 Hooks 尽快覆盖所有类的用例可能的.没有 Hook 等价物getSnapshotBeforeUpdate
和 componentDidCatch
生命周期,但我们计划很快添加它们.
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.
Hooks 还处于早期,所以一些集成,比如 DevTools支持或 Flow/TypeScript 类型可能还没有准备好.一些第三方库也可能与 Hooks 不兼容瞬间.
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.
这篇关于getSnapshotBeforeUpdate 使用反应钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!