Skip to content

Add useMemo/useCallback to context providers, fix broken react depend… - #529

Merged
YOGESH-08 merged 2 commits into
CodeChefVIT:stagingfrom
krishitag:fix/issue-471-usememo-usecallback
Aug 16, 2026
Merged

Add useMemo/useCallback to context providers, fix broken react depend…#529
YOGESH-08 merged 2 commits into
CodeChefVIT:stagingfrom
krishitag:fix/issue-471-usememo-usecallback

Conversation

@krishitag

Copy link
Copy Markdown
Contributor

Description

Fixes #471

Changes Made

  • Memoized Provider value objects in:

    • courseContext.tsx
    • filterContext.tsx
    • Card.tsx (PaperProvider)
    • carousel.tsx (CarouselContext)
  • Prevented unnecessary re-renders of context consumers when the Provider values have not changed.

  • Fixed the react dependency in package.json, restoring it to ^18.3.1 to match react-dom.

Verification

  • tsc --noEmit
  • pnpm build
  • pnpm lint

All checks pass successfully.

…ency

Fixes CodeChefVIT#471. Memoizes the Provider value objects in courseContext,
filterContext, Card's PaperProvider usage, and carousel.tsx's
CarouselContext, which were being rebuilt on every render and causing
unnecessary re-renders in consumers. Also fixes package.json, where
react was pinned via a broken link: path instead of a real version,
which broke local installs.
Comment thread src/context/filterContext.tsx Outdated
paginatedPapers,
totalPages,
};
const value: FilterContextType = useMemo(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting into 2 Contexts
Separate state (frequently changing) from actions (stable functions)

Addresses review feedback on the value memoization: separates
frequently-changing state (papers, filters, pagination) from stable
action functions into two contexts, so a future consumer that only
needs actions won't re-render on unrelated state changes. useFilters()
still works exactly as before for existing consumers.

@YOGESH-08 YOGESH-08 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@YOGESH-08
YOGESH-08 merged commit d35b0e0 into CodeChefVIT:staging Aug 16, 2026
1 check passed
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.

use useCallback, useMemo hooks for caching values

2 participants