-
Notifications
You must be signed in to change notification settings - Fork 1
wip: added a TanStackQueryProvider #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR migrates the project from react-query v3 to @tanstack/react-query v5, addressing breaking API changes and introducing a centralized query provider with global error handling.
Changes:
- Replaced
react-querywith@tanstack/react-queryv5 and updated all import statements - Created a new
TanStackQueryProvidercomponent with global error handling for 401 responses - Updated all
useQueryanduseMutationhooks to use the new v5 object-based configuration syntax
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| client/src/routes/root.tsx | Replaced QueryClientProvider setup with new TanStackQueryProvider component |
| client/src/pages/SearchPage.tsx | Updated to use new useSearchTrainee hook from data layer |
| client/src/hooks/useTraineeSearchData.tsx | Commented out old implementation (should be deleted) |
| client/src/hooks/useTraineeInfoData.tsx | Migrated useQuery and useMutation to v5 object syntax |
| client/src/hooks/useDashboardData.tsx | Migrated useQuery to v5 object syntax with inline data extraction |
| client/src/hooks/useCohortsData.tsx | Migrated useQuery to v5 object syntax with inline data extraction |
| client/src/hooks/interactions/interaction-queries.ts | Migrated all hooks to v5 syntax and improved error handling |
| client/src/hooks/education/test-queries.ts | Migrated all hooks to v5 object syntax |
| client/src/hooks/education/strike-queries.ts | Migrated useQuery to v5 object syntax |
| client/src/data/trainee/queries.ts | New file with useSearchTrainee hook implementation |
| client/src/data/tanstack/TanStackQueryProvider.tsx | New centralized provider with global error handling |
| client/src/components/education/TestsComponent.tsx | Updated import to use @tanstack/react-query |
| client/src/components/education/StrikesComponent.tsx | Updated import to use @tanstack/react-query |
| client/src/components/TraineeProfile.tsx | Updated import to use @tanstack/react-query |
| client/package.json | Added @tanstack/react-query packages and removed react-query |
| client/package-lock.json | Updated dependencies for the migration |
Files not reviewed (1)
- client/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| export const useSearchTrainee = (search: string) => { | ||
| return useQuery({ | ||
| queryKey: [queryKey], |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The queryKey for the search results is missing the 'search' parameter. This means all searches will use the same cache key, causing incorrect data to be returned. The queryKey should include the search parameter to ensure different searches have different cache entries.
| queryKey: [queryKey], | |
| queryKey: [queryKey, search], |
| queryKey: [queryKey], | ||
| queryFn: async () => { | ||
| const response = await axios.get(`/api/search?q=${search}&limit=20`); | ||
| console.log(response); |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Console.log statement should be removed. Debug logging should not be present in production code.
| console.log(response); |
| const resonse = await axios.get<Cohort[]>(`/api/cohorts`); | ||
| return resonse.data; |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: 'resonse' should be 'response'.
| const resonse = await axios.get<Cohort[]>(`/api/cohorts`); | |
| return resonse.data; | |
| const response = await axios.get<Cohort[]>(`/api/cohorts`); | |
| return response.data; |
| // /** | ||
| // * A React Query hook that fetches trainee search results form api. | ||
| // * | ||
| // * @param {string} search search keyword | ||
| // */ | ||
| // export const useTraineeSearchData = (search: string) => { | ||
| // return useQuery( | ||
| // { | ||
| // queryKey: ['search-results', search], | ||
| // } | ||
| // ['search-results', search], | ||
| // () => { | ||
| // return axios.get(`/api/search?q=${search}&limit=20`); | ||
| // }, | ||
| // { | ||
| // enabled: search.length > 1, // Query runs only if search string has more than 1 character | ||
| // select: (response) => { | ||
| // const trainees: SearchResult[] = response.data.hits.data.map((trainee: SearchResult) => trainee); | ||
| // return trainees; | ||
| // }, | ||
| // } | ||
| // ); | ||
| // }; |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entire file contains only commented-out code. Since the functionality has been moved to client/src/data/trainee/queries.ts, this file should be deleted rather than left with commented code. Keeping dead code increases maintenance burden and can cause confusion.
| import { StrikeDetailsModal } from './StrikeDetailsModal'; | ||
| import { StrikesList } from './StrikesList'; | ||
| import { useQueryClient } from 'react-query'; | ||
| import { useQueryClient } from '@tanstack/react-query'; |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The invalidateQueries API has changed in TanStack Query v5. Instead of passing an array directly, you should pass an object with a queryKey property. This should be: queryClient.invalidateQueries({ queryKey: ['strikes', traineeId] })
| } | ||
| ); | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries(['interactions', traineeId]); |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The invalidateQueries API has changed in TanStack Query v5. Instead of passing an array directly, you should pass an object with a queryKey property. This should be: queryClient.invalidateQueries({ queryKey: ['interactions', traineeId] })
| } | ||
| ); | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries(['interactions', traineeId]); |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The invalidateQueries API has changed in TanStack Query v5. Instead of passing an array directly, you should pass an object with a queryKey property. This should be: queryClient.invalidateQueries({ queryKey: ['interactions', traineeId] })
| refetchOnWindowFocus: false, | ||
| } | ||
| ); | ||
|
|
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the extra blank line. The query options should be consistently formatted without blank lines between properties.
| import { useQuery } from 'react-query'; | ||
| import axios from 'axios'; | ||
| import { SearchResult } from '../models'; | ||
| import axios from 'axios'; |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import axios.
| import axios from 'axios'; |
| import axios from 'axios'; | ||
| import { SearchResult } from '../models'; | ||
| import axios from 'axios'; | ||
| import { useQuery } from '@tanstack/react-query'; |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import useQuery.
| import { useQuery } from '@tanstack/react-query'; |
This is still wip