KratekK
tRPC3y ago
5 replies
Kratek

Generic handler for data.isLoading and data.isError

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?
Was this page helpful?