justinpark commented on code in PR #23760:
URL: https://github.com/apache/superset/pull/23760#discussion_r1179742309


##########
superset-frontend/src/hooks/apiResources/tables.ts:
##########
@@ -84,32 +93,60 @@ export function useTables(options: Params) {
     [schemaOptions],
   );
   const { dbId, schema, onSuccess, onError } = options || {};
-  const forceRefreshRef = useRef(false);
-  const params = { dbId, schema };
-  const result = useQuery<QueryData, Error, Data>(
-    ['tables', { dbId, schema }],
-    () => fetchTables({ ...params, forceRefresh: forceRefreshRef.current }),
+
+  const enabled = Boolean(
+    dbId && schema && !isFetching && schemaOptionsMap.has(schema),
+  );
+
+  const result = useTablesQuery(
+    { dbId, schema, forceRefresh: false },
     {
-      select: ({ json }) => ({
-        options: json.result,
-        hasMore: json.count > json.result.length,
-      }),
-      enabled: Boolean(
-        dbId && schema && !isFetching && schemaOptionsMap.has(schema),
-      ),
-      onSuccess,
-      onError,
-      onSettled: () => {
-        forceRefreshRef.current = false;
-      },
+      skip: !enabled,
     },
   );
+  const [trigger] = useLazyTablesQuery();
+
+  const refetch = useCallback(() => {
+    if (enabled) {
+      trigger({ dbId, schema, forceRefresh: true }).then(
+        ({ isSuccess, isError, data, error }) => {
+          if (isSuccess && data) {
+            onSuccess?.(data, true);
+          }
+          if (isError) {
+            onError?.(error as Response);
+          }
+        },
+      );
+    }
+  }, [dbId, schema, enabled]);
+
+  useEffect(() => {
+    if (isMountedRef.current) {

Review Comment:
   good call. I need to add `isMountedRef` on `schemas` api too



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to