Replies: 3 comments
-
I haven't really tried any of this myself, yet. There is a Also, |
Beta Was this translation helpful? Give feedback.
-
I am afraid this might be one of the limitations described during the Relay 11.0 release. Also a reason why Still, some parts of the hooks API are very much usable (fragments for example since they are not loading anything on their own) so you can start slowly migrating what's possible and ignore what's not possible. I think we will follow the Relay releases so no reason to panic. 😎 |
Beta Was this translation helpful? Give feedback.
-
I was able to make relay in your page: import { fetchQuery } from 'react-relay';
const fetchData = ({ environment, query, variables }) =>
new Promise((resolve, reject) => {
fetchQuery(environment, query, variables).subscribe({
complete: () => resolve(null),
error: (error) => reject(error),
});
});
export function getServerSideProps(ctx) {
await fetchData(environment, query, variables);
return {props: {records: environment.getStore().getSource().toJSON()}}
} Then in your _app function App({Component, pageProps: {records}}) {
const network = Network.create(fetchQuery);
const store = new Store(new RecordSource(records));
const environment = new Environment({
network,
store,
});
return <RelayEnvironmentProvider environment={environment}><Component /></RelayEnvironmentProvider>
} And somewhere in your app function LoadSomeData() {
const data = useLazyLoadQuery(
myQuery,
myVariables,
{ fetchPolicy: 'store-or-network' },
);
}
return <pre>{JSON.stringify(data, null, 2)}</pre> That way, your store should already be populated, and it won't need t o try to suspend on the server. |
Beta Was this translation helpful? Give feedback.
-
Hi guys, I started to investigate new relay hooks with NextJS. Currently I'm investigating on how to replace the
QueryRenderer
withuseLazyLoadQuery
. The problem I've stumbled upon is thatuseLazyLoadQuery
leverages theSuspense
to show loading state ie fallback andSuspense
doesn't really work when SSR-ing.I've tried something like this, because I get the data on the server so I can just use the cache(meaning the fallback wont be needed):
This works fine, but then I get a console warning about the html mismatching on the server and on the client, which makes sense since I'm essentially showing 2 different things on the server and on the client.
Any ideas how to handle this? If you already tried to tackle it
Beta Was this translation helpful? Give feedback.
All reactions