getting data from TRPC vs Zustand store

I need my component to prioritize data from a zustand store. If there's no data in the store, then fetch it from the server. I'm not sure if this is the correct way to do it?

Curious if this the best way to check if there's data in a Zustand store vs fetching and setting the data?
const fetchRequestedProduct =
    api.requestedProduct.getRequestedProductByTransactionIdAndProductId.useQuery(
      {
        transactionId,
        productId,
      },
      {
        enabled: requestedProductsInStore.get(productId) === undefined,
      }
    );

  useEffect(() => {
    const requestedProductsFromStore = requestedProductsInStore.get(productId);
    if (requestedProductsFromStore !== undefined) {
      setCurrentRequestedProducts(requestedProductsFromStore);
      return;
    }
    if (fetchRequestedProduct.data) {
      const requestedProducts: RequestedProductForTable[] =
        fetchRequestedProduct.data;
      setCurrentRequestedProducts(requestedProducts);
    }
  }, [
    fetchRequestedProduct.data,
    productId,
    requestedProductsInStore,
    setCurrentRequestedProducts,
  ]);
Was this page helpful?