Skip to content

Fix useEffect dependency issue by wrapping loadOrders with useCallback#46

Merged
AkibDa merged 2 commits intojeet-mainfrom
copilot/sub-pr-36-6a08f5b9-bb28-47fd-b9fa-b934c6ceadab
Jan 17, 2026
Merged

Fix useEffect dependency issue by wrapping loadOrders with useCallback#46
AkibDa merged 2 commits intojeet-mainfrom
copilot/sub-pr-36-6a08f5b9-bb28-47fd-b9fa-b934c6ceadab

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 17, 2026

The useEffect hook in AppContext.tsx had loadOrders in its dependency array, but the function was recreated on every render, causing unnecessary effect executions.

Changes

  • Wrapped loadOrders with useCallback and added userRole to its dependency array
  • Added useCallback to React imports

This ensures loadOrders has a stable reference that only changes when userRole changes, making the useEffect dependency array [userRole, loadOrders] work correctly.

// Before
const loadOrders = async () => {
  if (userRole !== UserRole.USER) return;
  // ... fetch logic
};

// After
const loadOrders = useCallback(async () => {
  if (userRole !== UserRole.USER) return;
  // ... fetch logic
}, [userRole]);

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: AkibDa <179389698+AkibDa@users.noreply.github.com>
@AkibDa AkibDa marked this pull request as ready for review January 17, 2026 17:54
Copilot AI changed the title [WIP] Address feedback from review on Jeet main pull request Fix useEffect dependency issue by wrapping loadOrders with useCallback Jan 17, 2026
@AkibDa AkibDa merged commit 77cc606 into jeet-main Jan 17, 2026
Copilot AI requested a review from AkibDa January 17, 2026 17:54
@AkibDa AkibDa deleted the copilot/sub-pr-36-6a08f5b9-bb28-47fd-b9fa-b934c6ceadab branch January 26, 2026 16:22
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.

2 participants