Skip to content

Commit 15148fe

Browse files
committed
Added docs for new features
1 parent 796c96c commit 15148fe

File tree

1 file changed

+81
-8
lines changed

1 file changed

+81
-8
lines changed

README.md

+81-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Feel free to contribute to the project by creating issues or pull requests.
2424
- [Features](#features)
2525
* [Shared data](#shared-data)
2626
* [Flash Messages](#flash-messages)
27+
* [Deferred props](#deferred-props)
28+
* [Merging props](#merging-props)
29+
* [History encryption](#history-encryption)
2730
* [Server-side rendering](#server-side-rendering)
2831
* [Vite helper](#vite-helper)
2932
- [Examples](#examples-1)
@@ -203,6 +206,83 @@ public async Task<IActionResult> Destroy(int id)
203206
}
204207
```
205208

209+
### Deferred props
210+
211+
Deferred props allow you to defer the loading of certain page data until after the initial page render. (see [Inertia.js docs](https://v2.inertiajs.com/deferred-props))
212+
213+
In the example below, the `Posts` prop will be loaded after the initial page render.
214+
215+
```csharp
216+
public IActionResult Profile()
217+
{
218+
return Inertia.Render("pages/Profile", new InertiaProps
219+
{
220+
["Foo"] = "Bar",
221+
["Posts"] = Inertia.Defer(async () =>
222+
{
223+
return await _context.Posts.ToListAsync();
224+
})
225+
});
226+
}
227+
```
228+
229+
> [!NOTE]
230+
> Deferred props are supported starting from Inertia.js v2.0
231+
232+
233+
### Merging props
234+
235+
By default, Inertia overwrites props with the same name when reloading a page. However, there are instances, such as pagination or infinite scrolling, where that is not the desired behavior. In these cases, you can merge props instead of overwriting them. (see [Inertia.js docs](https://v2.inertiajs.com/merging-props))
236+
237+
```csharp
238+
public IActionResult Users(int page, int perPage)
239+
{
240+
return Inertia.Render("pages/Users", new InertiaProps
241+
{
242+
["Results"] = Inertia.Merge(async () =>
243+
{
244+
return await GetPaginatedUsers(page, perPage);
245+
})
246+
});
247+
}
248+
```
249+
250+
> [!NOTE]
251+
> Merging props are supported starting from Inertia.js v2.0
252+
253+
### History encryption
254+
255+
See [Inertia.js docs](https://v2.inertiajs.com/history-encryption) for more information.
256+
257+
History encryption is an opt-in feature. There are several methods for enabling it:
258+
259+
#### Global encryption:
260+
261+
If you'd like to enable history encryption globally, set the `EncryptHistory` option to `true` in `AddInertia` method in `Program.cs`.
262+
263+
```csharp
264+
builder.Services.AddInertia(options =>
265+
{
266+
options.EncryptHistory = true;
267+
});
268+
```
269+
270+
#### Per-request encryption:
271+
To encrypt the history of an individual request, simply call the `Inertia.EncryptHistory()` method before returning the response.
272+
273+
```csharp
274+
Inertia.EncryptHistory();
275+
```
276+
277+
#### Clearing encrypted history:
278+
To clear the history state, you can call the `Inertia.ClearHistory()` method before returning the response.
279+
280+
```csharp
281+
Inertia.ClearHistory();
282+
```
283+
284+
> [!NOTE]
285+
> History encryption is supported starting from Inertia.js v2.0
206286
207287
### Server-side rendering
208288

@@ -328,11 +408,4 @@ export default defineConfig({
328408
emptyOutDir: true,
329409
},
330410
});
331-
```
332-
333-
334-
## Work in progress
335-
336-
- [x] Deferred props
337-
- [x] Merging props
338-
- [ ] History encryption
411+
```

0 commit comments

Comments
 (0)