-
Notifications
You must be signed in to change notification settings - Fork 63
Deep merge props #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deep merge props #213
Conversation
docs/guide/merging-props.md
Outdated
@@ -4,23 +4,35 @@ By default, Inertia overwrites props with the same name when reloading a page. H | |||
|
|||
## Server side | |||
|
|||
To specify that a prop should be merged, you can use the `merge` method on the prop value. | |||
> `deep_merge` requires `@inertiajs/core` v2.1.0 or higher, and `inertia_rails` v3.8.0 or higher. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version numbers are subject to change 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget it 😂 it's 2.0.8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks @HichemTab-tech!
9e54c92
to
6288dcf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great!
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. | ||
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. | ||
|
||
**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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good callout!
This PR adds support for deep merge props.
See inertiajs/inertia-laravel#679 and inertiajs/inertia#2069