13 Matching Annotations
  1. Last 7 days
    1. So the clock component becomes something like this — we express componentDidMount and componentDidUnmount in terms of a useEffect with an empty dependencies array, and componentDidUpdate in terms of a useEffect with explicit dependencies.

    1. Rather than thinking of useEffect as one function doing the job of 3 separate lifecycles, it might be more helpful to think of it simply as a way to run side effects after render – including the potential cleanup you’d want to do before each one, and before unmounting.
    2. With useEffect, you can handle lifecycle events directly inside function components. Namely, three of them: componentDidMount, componentDidUpdate, and componentWillUnmount. All with one function!
  2. Apr 2020
    1. Promises and useEffect(async () => ...) are not supported, but you can call an async function inside an effect.. That's why using async directly in the useEffect function isn't allowed.

      async and useEffect

  3. Sep 2019
  4. Aug 2019
    1. However, using the local storage in React's function components is a side-effect which is best implemented with the Effect Hook which runs every time the value property changes: