Generic handler for data.isLoading and data.isError

KKratek4/27/2023
Hi, I'm looking for a way to create generic interface for useQuery result (budgetData from example below). My aim is to create generic function that handle isLoading and isError in every component.

Example below:

const budgetData = api.budgets.getAllBudgets.useQuery();

  if (budgetData.isLoading) {
    return;
  }

  if (budgetData.isError) {
    router.push(Routes.ERROR_500);
    return null;
  }

Could you help me with it guys?
Nnlucas4/27/2023
Typescript is structurally typed so if all you want is those two then ‘{ isLoading: boolean , isError: boolean }’ is your type
Nnlucas4/27/2023
But you’re probably doing something weird
Nnlucas4/27/2023
Maybe you want to start using Suspense and ErrorBoundaries instead?