react break out of useeffect 1

react break out of useeffect

React.useEffect(() => {
  if (foo){
    // do something
  }
})


React.useEffect(() => {
  if (!foo){
    return;
  }

  // do something
})

Here is what the above code is Doing:
1. The first useEffect is called every time the component renders.
2. The second useEffect is called only when the component mounts and when foo changes.

Similar Posts