Problem
The UserProvider component recreates its value object on every render (e.g., value={{ user, setUser }}).
Since the object reference changes on each render, all context consumers re-render, causing unnecessary updates and performance degradation throughout the app.
Points: 30
Steps to Reproduce
- Load the application with
UserProvider wrapping multiple components.
- Trigger any state change inside the provider (e.g., updating user info, logging in/out).
- Observe consumer components via React DevTools or console logs.
- Notice:
- All components using
UserContext re-render even if their dependent data didn't change.
- This causes a render storm and performance issues.
Expected Behavior
The context value should have a stable reference unless the underlying user data actually changes.
To achieve this:
- Wrap the context value in
useMemo, for example:
const value = useMemo(() => ({ user, setUser }), [user]);
##Submission Guidelines
1.Comment on this issue with your proposed solution approach.
2.Wait for issue assignment from reviewers.
3.Create a PR with clear, descriptive commit messages.
4.Reference this issue in your PR description.
Problem
The
UserProvidercomponent recreates itsvalueobject on every render (e.g.,value={{ user, setUser }}).Since the object reference changes on each render, all context consumers re-render, causing unnecessary updates and performance degradation throughout the app.
Points: 30
Steps to Reproduce
UserProviderwrapping multiple components.UserContextre-render even if their dependent data didn't change.Expected Behavior
The context value should have a stable reference unless the underlying user data actually changes.
To achieve this:
useMemo, for example:##Submission Guidelines
1.Comment on this issue with your proposed solution approach.
2.Wait for issue assignment from reviewers.
3.Create a PR with clear, descriptive commit messages.
4.Reference this issue in your PR description.