Last active
August 27, 2021 13:16
-
-
Save ziedHamdi/eed7dff4f99fbf13216e33b988797df2 to your computer and use it in GitHub Desktop.
Ssr with Apollo and Next.js: code in page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {gql, useQuery} from '@apollo/client' | |
import {Grid} from "@material-ui/core"; | |
import {serverSideTranslations} from 'next-i18next/serverSideTranslations'; | |
import {addApolloState, initializeApollo} from '../apollo/client' | |
import {getDataFromTree} from "@apollo/client/react/ssr"; | |
export async function getServerSideProps(context) { | |
const client = initializeApollo({}) | |
// await getDataFromTree(SsrPage) (not working: see bug report) | |
const query1 = await client.query({query: ComplaintsQuery}) | |
const query2 = await client.query({query: TrendingComplaintsQuery}) | |
const {locale} = context | |
const documentProps = addApolloState(client, { | |
props: {...(await serverSideTranslations(locale, ['header', 'complaintList', 'footer']))}, | |
}) | |
// Will be passed to the page component as props | |
return {props: documentProps.props} | |
} | |
export default function SsrPage(props) { | |
//your react standard code here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment