rsnext/examples/with-zustand/pages/ssr.js
Munawwar bb7b75809d
update zustand example (#35022)
Made SSG and SSR code similar. Comments and variable renames on store.js

Checklist:

## Documentation / Examples

- [✓] Make sure the linting passes by running `yarn lint`
2022-05-22 04:57:40 +00:00

20 lines
699 B
JavaScript

import Page from '../components/page'
import { initializeStore } from '../lib/store'
export default function SSR() {
return <Page />
}
// The date returned here will be different for every request that hits the page,
// that is because the page becomes a serverless function instead of being statically
// exported when you use `getServerSideProps` or `getInitialProps`
export function getServerSideProps() {
const zustandStore = initializeStore()
return {
props: {
// the "stringify and then parse again" piece is required as next.js
// isn't able to serialize it to JSON properly
initialZustandState: JSON.parse(JSON.stringify(zustandStore.getState())),
},
}
}