Skip to content

Commit

Permalink
docs: Move section
Browse files Browse the repository at this point in the history
  • Loading branch information
frandiox committed Apr 4, 2021
1 parent 1996b10 commit 505e346
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,30 @@ function App({ router }) {
</p>
</details>
### State serialization
Vite SSR simply uses `JSON.stringify` to serialize the state and saves it in the DOM. This behavior can be overriden by using the `transformState` hook:
```js
import viteSSR from 'vite-ssr'
import App from './app'
import routes from './routes'

export default viteSSR(App, {
routes,
transformState(state) {
if (import.meta.state.SSR) {
// Serialize during SSR by using,
// for example, @nuxt/devalue
return customSerialize(state)
} else {
// Deserialize in browser
return customDeserialize(state)
}
},
})
```
## Head tags and global attributes
Use your framework's utilities to handle head tags and attributes for html and body elements.
Expand Down Expand Up @@ -303,30 +327,6 @@ import { Helmet } from 'react-helmet-async'
</p>
</details>
## State serialization
Vite SSR simply uses `JSON.stringify` to serialize the state and saves it in the DOM. This can be changed by using the `transformState` hook:
```js
import viteSSR from 'vite-ssr'
import App from './app'
import routes from './routes'

export default viteSSR(App, {
routes,
transformState(state) {
if (import.meta.state.SSR) {
// Serialize during SSR by using,
// for example, @nuxt/devalue
return customSerialize(state)
} else {
// Deserialize in browser
return customDeserialize(state)
}
},
})
```
## Rendering only in client/browser
Vite SSR exports `ClientOnly` component that renders its children only in the browser:
Expand Down

0 comments on commit 505e346

Please sign in to comment.