Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Commit

Permalink
examples(react): state serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
galvez committed Jun 30, 2022
1 parent fdc6a10 commit a21dc2b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion starters/react/client/pages/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logo from '/assets/logo.svg'
import { Link } from 'react-router-dom'
import { isServer, useRouteContext } from '/dx:core.jsx'

export function getMeta () {
return {
Expand All @@ -8,10 +9,15 @@ export function getMeta () {
}

export default function Index () {
const { snapshot, state } = useRouteContext()
if (isServer) {
// State is automatically hydrated on the client
state.message = 'Welcome to Fastify DX for React!'
}
return (
<>
<img src={logo} />
<h1>Welcome to Fastify DX for React!</h1>
<h1>{snapshot.message}</h1>
<ul className="columns-2">
<li><Link to="/using-data">/using-data</Link> demonstrates how to
leverage the <code>getData()</code> function
Expand Down

0 comments on commit a21dc2b

Please sign in to comment.