Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ryokomy
Copy link

@ryokomy ryokomy commented Jul 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant