#useResources ... how to actually use it

6 messages · Page 1 of 1 (latest)

old furnace
#

so i have useResource hook, as i read the articles from the docs, it says that useResources is doing the first on the server and after from the client

#

but when navigating from x to my page it s not doing any requests

#

the code for the useResources:

 const myResources = useResource$(async ({ track }) => {
    track(() => wishService.state.refresh);
    try {
      console.log("AM INTART PRIMA DATA");
      console.log(isServer && userCookieToken.value.token);
      if (isServer && userCookieToken.value.token) {
        const resData = await ServerActionReq.getWishBoxAndWishes(
          userCookieToken.value.token
        );
        console.log(resData, isServer, "SERVER");
        if (resData?.data) {
          return resData.data;
        }
      }
      if (isBrowser && authService.state.user.token) {
        loadingState.simpleLoading = true;
        const resData = await wishService.getWishBoxAndWishes();
        if (resData?.data) {
          wishService.state.createWishHighlight = !resData.data.length;
          return resData.data;
        }
      }
    } catch (err) {
      console.log("Error getWishBoxAndWishes", err);
    } finally {
      loadingState.simpleLoading = false;
    }
  });
#

at this point when i refresh it triggers on navigation it dosent

#

useVisibleTask should't suppose to trigger api calls

#

but how and what to use