Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit 2fa865f

Browse files
authored
docs(ssr): pass renderToString to getServerState in examples (#3659)
Followup on #3658, to be merged close to the release EDIT: actually this can be merged before the release already as previously the unused argument wasn't used
1 parent 9c10449 commit 2fa865f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

examples/hooks-next/pages/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Head from 'next/head';
22
import { GetServerSideProps } from 'next';
3+
import { renderToString } from 'react-dom/server';
34
import algoliasearch from 'algoliasearch/lite';
45
import { Hit as AlgoliaHit } from 'instantsearch.js';
56
import {
@@ -87,7 +88,9 @@ export const getServerSideProps: GetServerSideProps<HomePageProps> =
8788
async function getServerSideProps({ req }) {
8889
const protocol = req.headers.referer?.split('://')[0] || 'https';
8990
const url = `${protocol}://${req.headers.host}${req.url}`;
90-
const serverState = await getServerState(<HomePage url={url} />);
91+
const serverState = await getServerState(<HomePage url={url} />, {
92+
renderToString,
93+
});
9194

9295
return {
9396
props: {

examples/hooks-ssr/src/server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ app.get('/', async (req, res) => {
1313
const location = new URL(
1414
`${req.protocol}://${req.get('host')}${req.originalUrl}`
1515
);
16-
const serverState = await getServerState(<App location={location} />);
16+
const serverState = await getServerState(<App location={location} />, {
17+
renderToString,
18+
});
1719
const html = renderToString(
1820
<App serverState={serverState} location={location} />
1921
);

0 commit comments

Comments
 (0)