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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user