-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relay: loadQuery
should not be called inside a React render function.
#3449
Comments
Same issue here. This seems extremely counterintuitive: How do I pass the variables to loadQuery, if it's not called in the functional component? To load a specific entity, I need its ID, which I get from either context or props and these are only accessible within the functional component. Am I missing something huge here? V11 is a huge departure from V10, I hope this is for the better long-term, as it is causing us lots of headaches with understanding how everything functions now. |
Note that
Note that loadQuery() + usePreloadedQuery() generally requires more setup to use. The easiest way to get started fetching data is with |
I was able to finally loosely grasp how everything is supposed to work by looking at the migration section here: https://relay.dev/docs/migration-and-compatibility/relay-hooks-and-legacy-container-apis/ The hooks documentation is very confusing for someone like me coming from the Legacy APIs. |
Just ran into this issue, and now I have to rethink everything.
This was my exact thinking. How have others approached this problem? |
@jamietdavidson check out this example: Go through it thoroughly and you will get a rough idea. |
@jamietdavidson That's a reasonable use-case for |
Got it. It needed to be wrapped in Suspense. While this is completely my bad, I have to say that I found this article was alot easier to follow than the Relay docs. I also had to use an In any case, I hope this offers some help to anyone else that stumbles into this problem as a beginner to React (like myself). The // Load root graph data
React.useEffect(() => {
const queryRef = loadQuery(environment, query, { uid: rootQueryId });
setRootQueryRef(queryRef);
}, [rootQueryId]); Best, |
@jamietdavidson Note that the example usage of Stated conversely, we only recommend |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@josephsavona Suppose a component has two queries to fire. In that case, calling useLazyLoadQuery twice will result in a waterfall. What's the recommendation in this case? Obviously preloading both queries is ideal, but working with nextjs its not quite feasible yet. I thought a loadQuery in useRef/useMemo might be a good compromise, but it would trigger loadQuery during render. |
recently ran into a similar issue with Storybook and decorators. FWIW — |
A point of confusion can arise in connection with the docs for
This makes it sound like |
I created a RelayTestComponent for re-use during testing
Then I have a component which uses
preloadedQuery
and renders the component im trying to test:Im my test I do:
But now im getting this error for every test after the 1st test:
The text was updated successfully, but these errors were encountered: