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

Commit fd190d1

Browse files
committed
fix
1 parent 1ff1397 commit fd190d1

File tree

4 files changed

+45
-41
lines changed

4 files changed

+45
-41
lines changed

docs/react/basic-setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
The [starter template](https://github.com/fastify/fastify-dx/tree/dev/starters/react) follows [fastify-vite](https://github.com/fastify/fastify-vite)'s convention of having a `client` folder with an `index.js` file, which is automatically resolved as your `clientModule` setting.
88

9-
If you want flat directory setup, where server and client files are mixed together, you can manually set `clientModule` to something else. Note that in this case you'll also need to update `root` in your `vite.config.js` file.
9+
If you want a flat directory setup, where server and client files are mixed together, you can manually set `clientModule` to something else. Note that in this case you'll also need to update `root` in your `vite.config.js` file.
1010

1111
When deploying to production, bear in mind the `client/dist` directory, generated when you run `npm run build`, needs to be included. You'll also want to enable Fastify's [built-in logging](https://www.fastify.io/docs/latest/Reference/Logging/):
1212

docs/react/project-structure.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ The [starter template](https://github.com/fastify/fastify-dx/tree/dev/starters/r
1010
```
1111
├── server.js
1212
├── client/
13-
├── index.js
14-
├── context.js
15-
├── root.jsx
16-
├── index.html
17-
├── layouts/
18-
├── default.jsx
19-
└── auth.jsx
20-
└── pages/
21-
├── index.jsx
22-
├── client-only.jsx
23-
├── server-only.jsx
24-
├── streaming.jsx
25-
├── using-data.jsx
26-
└── using-store.jsx
13+
├── index.js
14+
├── context.js
15+
├── root.jsx
16+
├── index.html
17+
├── layouts/
18+
├── default.jsx
19+
└── auth.jsx
20+
└── pages/
21+
├── index.jsx
22+
├── client-only.jsx
23+
├── server-only.jsx
24+
├── streaming.jsx
25+
├── using-data.jsx
26+
└── using-store.jsx
2727
├── vite.config.js
2828
└── package.json
2929
```

docs/react/route-context.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,29 @@ This example demonstrates how to use it to set up an universally available (SSR
3333
import ky from 'ky-universal'
3434

3535
export default (ctx) => {
36-
// This runs both on the server and on the
37-
// client, exactly once per HTTP request
38-
ctx.message = 'Universal hello'
3936
if (ctx.server) {
40-
// Place some server data on the
41-
// application's global state
42-
ctx.state = ctx.server.db
43-
// It is automatically hydrated on the client
44-
// So no need to any additional assignments here
37+
// Populate state.todoList on the server
38+
ctx.state.todoList = ctx.server.db.todoList
39+
// It'll get automatically serialized to the client on first render!
4540
}
4641
}
4742

4843
export const $fetch = ky.extend({
4944
prefixUrl: 'http://localhost:3000'
5045
})
5146

52-
export async function addTodoItem (state, item) {
53-
await $fetch.put('api/todo/items', {
54-
body: { item },
55-
})
56-
state.todoList.push(item)
47+
// Must be a function so each request can have its own state
48+
export const state = () => ({
49+
todoList: null,
50+
})
51+
52+
export const actions = {
53+
async addTodoItem (state, item) {
54+
await $fetch.put('api/todo/items', {
55+
json: { item },
56+
})
57+
state.todoList.push(item)
58+
},
5759
}
5860
```
5961

docs/vue/route-context.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,29 @@ This example demonstrates how to use it to set up an universally available (SSR
3333
import ky from 'ky-universal'
3434

3535
export default (ctx) => {
36-
// This runs both on the server and on the
37-
// client, exactly once per HTTP request
38-
ctx.message = 'Universal hello'
3936
if (ctx.server) {
40-
// Place some server data on the
41-
// application's global state
42-
ctx.state = ctx.server.db
43-
// It is automatically hydrated on the client
44-
// So no need to any additional assignments here
37+
// Populate state.todoList on the server
38+
ctx.state.todoList = ctx.server.db.todoList
39+
// It'll get automatically serialized to the client on first render!
4540
}
4641
}
4742

4843
export const $fetch = ky.extend({
4944
prefixUrl: 'http://localhost:3000'
5045
})
5146

52-
export async function addTodoItem (state, item) {
53-
await $fetch.put('api/todo/items', {
54-
body: { item },
55-
})
56-
state.todoList.push(item)
47+
// Must be a function so each request can have its own state
48+
export const state = () => ({
49+
todoList: null,
50+
})
51+
52+
export const actions = {
53+
async addTodoItem (state, item) {
54+
await $fetch.put('api/todo/items', {
55+
json: { item },
56+
})
57+
state.todoList.push(item)
58+
},
5759
}
5860
```
5961

0 commit comments

Comments
 (0)