Memoize parameters for useInstance (#11652)

This commit is contained in:
Oliver 2026-04-01 17:06:38 +11:00 committed by GitHub
parent 080edc870f
commit c89b0b7131
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 8 deletions

View File

@ -56,16 +56,14 @@ export function useInstance<T = any>({
const [instance, setInstance] = useState<T | undefined>(defaultValue);
// A memoized key to track changes in the params and pathParams
const paramsKey = useMemo(() => {
return JSON.stringify(params) + JSON.stringify(pathParams);
}, [params, pathParams]);
const instanceQuery = useQuery<T>({
enabled: !disabled,
queryKey: [
'instance',
endpoint,
pk,
JSON.stringify(params),
JSON.stringify(pathParams),
disabled
],
queryKey: ['instance', endpoint, pk, paramsKey, disabled],
retry: (failureCount, error: any) => {
// If it's a 404, don't retry
if (error.response?.status == 404) {