Skip to content

Context render bomb #3

Description

@sengardeep

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

  1. Load the application with UserProvider wrapping multiple components.
  2. Trigger any state change inside the provider (e.g., updating user info, logging in/out).
  3. Observe consumer components via React DevTools or console logs.
  4. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Mediummedium issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions