9 Matching Annotations
  1. Nov 2019
  2. Sep 2019
    1. The equivalent ways in functional components using Hooks:In a state variable: useState or useReducer. Updates in state variables will cause a re-render of the component.In a ref: Equivalent to instance variables in class components. Mutating the .current property won’t cause a re-render.
    1. const isFirst = useRef(true)
    2. You can also create your own custom hook that uses the useRef hook to keep track of if it's the first time the effect is being run, so that you can skip the first invocation.
  3. Aug 2019
    1. const useFocus = () => { const htmlElRef = useRef(null) const setFocus = () => {htmlElRef.current && htmlElRef.current.focus()} return [ setFocus, htmlElRef ] }

      exampleOf: useRef exampleOf: custom hook