Primarily refines dependency arrays in React hooks to prevent unnecessary re-renders and refetch loops ➿#562
Merged
Conversation
Add comment to clarify dependency omission in useEffect.
…and invalid defaultValue prop Co-authored-by: jamespepper81 <84083764+jamespepper81@users.noreply.github.com>
…ependencies fix(AnimatedNumber): remove stable shared value refs from dep arrays and invalid defaultValue prop
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refines React hook dependency arrays to reduce unnecessary effect re-runs/refetch loops, with a small TypeScript type annotation tweak and a minor cleanup in an animation component.
Changes:
- Adjusts hook dependency arrays and adds rationale comments / eslint disables where deps are intentionally omitted.
- Cleans up
AnimatedNumberderived value return shape by removing an unused property. - Tweaks a
WalletService-key array type annotation for clarity.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
components/AnimatedNumber.tsx |
Updates useEffect deps / eslint disables for shared values; removes defaultValue from derived return object. |
app/wallet-setup.tsx |
Changes requiredFunctions type annotation to Array<keyof WalletService>. |
app/(tabs)/receive.tsx |
Adds an inline comment clarifying why certain deps are intentionally omitted for a useEffect. |
Comments suppressed due to low confidence (2)
components/AnimatedNumber.tsx:40
- These effects now rely on an eslint-disable for exhaustive-deps solely to omit
animatedValue. SinceuseSharedValuereturns a stable ref, keepinganimatedValuein the dependency array won’t cause re-runs but does avoid suppressing the lint rule. Consider re-addinganimatedValueto the deps and removing the eslint-disable here to reduce lint suppressions.
useEffect(() => {
animatedValue.value = withTiming(value, { duration });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [value, duration]); // animatedValue is a stable shared value ref and should not be in deps
components/AnimatedNumber.tsx:50
- Same as above: omitting the stable
scaleshared value forces an eslint-disable. Includingscalein the dependency array should be harmless (stable ref) and lets you remove the exhaustive-deps suppression.
useEffect(() => {
scale.value = withSpring(1.02, { damping: 8, stiffness: 300 }, () => {
scale.value = withSpring(1, { damping: 15, stiffness: 400 });
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [value]); // scale is a stable shared value ref and should not be in deps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request primarily refines dependency arrays in React hooks to prevent unnecessary re-renders and refetch loops. It also includes a minor type improvement and removes an unused property. These changes help optimize performance and clarify intent in the codebase.
React hook dependency optimizations:
app/(tabs)/receive.tsx: Added a comment explaining why certain dependencies (walletServiceand stable setters/callbacks) are intentionally omitted from theuseEffectdependency array to avoid unnecessary refetch loops.components/AnimatedNumber.tsx: Removed stable shared value refs (animatedValue,scale) fromuseEffectdependency arrays, with comments clarifying their omission and ESLint disables for clarity. [1] [2]Codebase cleanup:
components/AnimatedNumber.tsx: Removed the unuseddefaultValueproperty from the return object in theuseDerivedValuehook.Type improvement:
app/wallet-setup.tsx: Changed the type annotation forrequiredFunctionsto useArray<keyof WalletService>for clarity and consistency.