React27Hooks usage rules

  • Hooks called only at the top level
    • Hooks try to call the call only at the top level scope
    • Do not call Hook in circulation, condition or nested function, it may not be able to ensure that all calls Hook in the same order each time the component rendering. Hook plurality of hooks are used to determine the sequence, with the proviso that the order of the rendering may break.
  • Only function component calls Hooks
    • React Hooks currently only supports function components, so we do not call Hook hook function or normal function in class components inside
  • React Hooks application scenario as follows
    • Function Component
    • You deliberately hooks at their own expense
  • React Hooks in future versions will be extended to class components, but at this stage can not be used in class
 

Guess you like

Origin www.cnblogs.com/tengfeiS/p/12164448.html