From 98eaa14eee03126b9d46351e5a72b2fa8bd441df Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 18 Sep 2023 23:24:05 +1000 Subject: [PATCH] Fix useInstance hook (#5567) --- src/frontend/src/hooks/UseInstance.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/frontend/src/hooks/UseInstance.tsx b/src/frontend/src/hooks/UseInstance.tsx index 7da5eaeaf1..8f36c9b879 100644 --- a/src/frontend/src/hooks/UseInstance.tsx +++ b/src/frontend/src/hooks/UseInstance.tsx @@ -21,8 +21,12 @@ export function useInstance( const instanceQuery = useQuery({ queryKey: ['instance', url, pk, params], - enabled: pk != null && pk != undefined && pk.length > 0, queryFn: async () => { + if (pk == null || pk == undefined || pk.length == 0) { + setInstance({}); + return null; + } + return api .get(url + pk + '/', { params: params @@ -47,12 +51,9 @@ export function useInstance( refetchOnWindowFocus: false }); - const refreshInstance = useCallback( - function () { - instanceQuery.refetch(); - }, - [instanceQuery] - ); + const refreshInstance = useCallback(function () { + instanceQuery.refetch(); + }, []); return { instance, refreshInstance, instanceQuery }; }