tutorials
tutorials copied to clipboard
Fix: Add cleanup function to useEffect in 03-client-step7
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
useEffecthook to set a cancellation flag (isCancelled) when thecounterContractvalue changes or the component unmounts. - The recursive
getValuefunction now checks theisCancelledflag to determine whether to continue execution.
Testing
- Verified that the recursive function stops when
counterContractchanges. - Ensured that no memory leaks or unnecessary API calls occur.
Related Issues
- Fixes potential memory leak and unnecessary API calls in
useCounterContract.