2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-04-09 04:51:09 +00:00

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

View File

@@ -56,16 +56,14 @@ export function useInstance<T = any>({
const [instance, setInstance] = useState<T | undefined>(defaultValue); 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>({ const instanceQuery = useQuery<T>({
enabled: !disabled, enabled: !disabled,
queryKey: [ queryKey: ['instance', endpoint, pk, paramsKey, disabled],
'instance',
endpoint,
pk,
JSON.stringify(params),
JSON.stringify(pathParams),
disabled
],
retry: (failureCount, error: any) => { retry: (failureCount, error: any) => {
// If it's a 404, don't retry // If it's a 404, don't retry
if (error.response?.status == 404) { if (error.response?.status == 404) {