2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-04-02 17:41:13 +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);
// 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) {