Summary on pit

  • useState:
    • As a component constant, personally understood as a component dependency, each update of state causes the entire component to be updated again
    • UseState (() => {console.log(‘ initialize once ‘)}), when useState defaults to a function, the function will be executed once at initialization instead of once. Official definition: lazy initialization. UseState (() => () => {})
    • SetState (‘a’, () => {})
  • useRef:
    • UseRef does not define a component dependency, so his changes do not cause the component to re-perform updates