T

tRPC

❓-help

Join Server

Delay IsLoading....

AAyo11/24/2022
i'm trying to delay a loading spinner from appearing if the api takes less than 200ms to get the data. I've tried a number of implementations and failed, can anyone help?

  const { isLoading, isError, data } = trpc.ticketDomain.getByTicketId.useQuery(
    {
      ticketId: selectedTicket!.id,
    }
  );

  if (isLoading) {
    // details section should not render if isloading has been true for 200ms or                 less and if 'data' is not available

    // load data as soon as its available and render the details section

    // if fetching takes longer than 200ms, show loading spinner
    return (

        <LoadingSpinner />;
    
    );
  }
UUUnknown User11/24/2022
2 Messages Not Public
Sign In & Join Server To View
AAyo11/25/2022
Thank you for getting back to me with these solutions. I'm ganna read over them and implement. πŸ™πŸΎ
Ttrash_dev11/25/2022
You’re still gonna have issues with it flashing a spinner
Ttrash_dev11/25/2022
not sure if you want to artificially show the spinner for x time if it resolves immediately after 200ms

I use promise.race for these