2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

Fix useInstance hook (#5567)

This commit is contained in:
Oliver 2023-09-18 23:24:05 +10:00 committed by GitHub
parent 981bfa344b
commit 98eaa14eee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,8 +21,12 @@ export function useInstance(
const instanceQuery = useQuery({ const instanceQuery = useQuery({
queryKey: ['instance', url, pk, params], queryKey: ['instance', url, pk, params],
enabled: pk != null && pk != undefined && pk.length > 0,
queryFn: async () => { queryFn: async () => {
if (pk == null || pk == undefined || pk.length == 0) {
setInstance({});
return null;
}
return api return api
.get(url + pk + '/', { .get(url + pk + '/', {
params: params params: params
@ -47,12 +51,9 @@ export function useInstance(
refetchOnWindowFocus: false refetchOnWindowFocus: false
}); });
const refreshInstance = useCallback( const refreshInstance = useCallback(function () {
function () {
instanceQuery.refetch(); instanceQuery.refetch();
}, }, []);
[instanceQuery]
);
return { instance, refreshInstance, instanceQuery }; return { instance, refreshInstance, instanceQuery };
} }