Skip to content

Fix: Memoize NetworkContext value to prevent unnecessary re-renders#47

Open
VineetC137 wants to merge 1 commit intoDjedAlliance:mainfrom
VineetC137:fix-networkcontext-usememo
Open

Fix: Memoize NetworkContext value to prevent unnecessary re-renders#47
VineetC137 wants to merge 1 commit intoDjedAlliance:mainfrom
VineetC137:fix-networkcontext-usememo

Conversation

@VineetC137
Copy link

@VineetC137 VineetC137 commented Jan 22, 2026

What

  • Memoized the value object passed to NetworkContext.Provider.

Why

  • Previously, a new object was created on every render, forcing all consumers to re-render unnecessarily.

How

  • Wrapped the provider value in useMemo with appropriate dependencies.

Testing

  • Verified the application runs correctly and network related UI flows still work.

Fixes #43

Summary by CodeRabbit

  • Refactor
    • Enhanced network context performance through memory optimization.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

The NetworkContext value is wrapped in useMemo to prevent unnecessary re-renders of consuming components when the NetworkProvider re-renders, addressing a performance optimization issue where the context value object was recreated on every render.

Changes

Cohort / File(s) Summary
Network Context Memoization
stablepay-sdk/src/contexts/NetworkContext.jsx
Added useMemo import and wrapped the NetworkContext value object in useMemo to prevent recreating the context value on every render, reducing unnecessary re-renders of components consuming the useNetwork hook

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🐰 A context that hops without care,
Now memoized through the air,
No needless re-renders in sight,
Performance shines so bright! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: memoizing NetworkContext value to prevent unnecessary re-renders, which matches the core objective of the PR.
Linked Issues check ✅ Passed The PR successfully addresses issue #43 by implementing useMemo for NetworkContext value, preventing unnecessary re-renders of consumer components when data hasn't changed.
Out of Scope Changes check ✅ Passed All changes are scoped to NetworkContext.jsx and directly address the performance optimization objective; no unrelated modifications were introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@VineetC137
Copy link
Author

Thanks for reviewing this.
I see that @aniket866 has also opened a PR (#48) addressing this issue with a broader approach.
Happy to defer to whichever solution the maintainers feel is more appropriate.
Please feel free to close this PR if the other implementation is preferred.

@aniket866
Copy link

aniket866 commented Jan 23, 2026

After creating issue,
i had committed the changes on the same day locally ,but waiting for maintainer , so today I raised those commits

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.

Network optimization :Missing useMemo for Context Values (NetworkContext.jsx)

2 participants