You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/merging-props.md
+35-11Lines changed: 35 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,23 +4,37 @@ By default, Inertia overwrites props with the same name when reloading a page. H
4
4
5
5
## Server side
6
6
7
-
To specify that a prop should be merged, you can use the `merge` method on the prop value.
7
+
> `deep_merge` requires `@inertiajs/core` v2.0.8 or higher, and `inertia_rails` v3.8.0 or higher.
8
+
9
+
To specify that a prop should be merged, use the `merge` or `deep_merge` method on the prop's value.
10
+
11
+
Use `merge` for merging simple arrays, and `deep_merge` for handling nested objects that include arrays or complex structures, such as pagination objects.
On the client side, Inertia detects that this prop should be merged. If the prop returns an array, it will append the response to the current prop value. If it's an object, it will merge the response with the current prop value.
35
+
On the client side, Inertia detects that this prop should be merged. If the prop returns an array, it will append the response to the current prop value. If it's an object, it will merge the response with the current prop value. If you have opted to `deepMerge`, Inertia ensures a deep merge of the entire structure.
36
+
37
+
**Of note:** During the merging process, if the value is an array, the incoming items will be _appended_ to the existing array, not merged by index.
24
38
25
39
You can also combine [deferred props](/guide/deferred-props) with mergeable props to defer the loading of the prop and ultimately mark it as mergeable once it's loaded.
26
40
@@ -29,8 +43,18 @@ class UsersController < ApplicationController
0 commit comments