tutorials icon indicating copy to clipboard operation
tutorials copied to clipboard

Fix: Add cleanup function to useEffect in 03-client-step7

Open ryokomy opened this issue 7 months ago • 0 comments

Description

This PR addresses an issue in the useCounterContract hook where the useEffect hook's recursive function could continue running even after the counterContract value changes. This could potentially lead to memory leaks and unnecessary API calls.

Changes

  • Added a cleanup function to the useEffect hook to set a cancellation flag (isCancelled) when the counterContract value changes or the component unmounts.
  • The recursive getValue function now checks the isCancelled flag to determine whether to continue execution.

Testing

  • Verified that the recursive function stops when counterContract changes.
  • Ensured that no memory leaks or unnecessary API calls occur.

Related Issues

  • Fixes potential memory leak and unnecessary API calls in useCounterContract.

ryokomy avatar Jul 23 '24 08:07 ryokomy