zjffun blog

React Hooks

更新于 写于 前端

  • Hooks allow you to reuse stateful logic without changing your component hierarchy.
  • Hooks let you split one component into smaller functions based on what pieces are related (such as setting up a subscription or fetching data),

Rules of Hooks

  • Only Call Hooks at the Top Level
  • Only Call Hooks from React Functions

Because React relies on the order in which Hooks are called.