RevereCRE / relay-nextjs

⚡️ Relay integration for Next.js apps
https://reverecre.github.io/relay-nextjs/
MIT License
250 stars 30 forks source link

WIP: Ability to pass loadQuery to page #30

Closed 0xHexE closed 2 years ago

0xHexE commented 2 years ago

Because https://relay.dev/docs/guided-tour/refetching/refetching-queries-with-different-data/#when-using-usequeryloader--loadquery we can re-fetch the query using load query in some questions

0xHexE commented 2 years ago

Never mind you can use fetchQuery something like this.


  const [isRefreshing, setIsRefreshing] = useState(false);
  const environment = useRelayEnvironment();

  useEffect(() => {
    if (isRefreshing) {
      return;
    }

    setIsRefreshing(true);

    fetchQuery(
      environment as never,
      CartQuery,
      preloadedQuery.variables
    ).subscribe({
      complete: () => {
        setIsRefreshing(false);
      },
      error: () => {
        setIsRefreshing(false);
      },
    });
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [atomValue]);

it will re-fetch the query.

But can be good for re-fetching with different params.