You're viewing the Inertia.js v2.0 documentation. Upgrade guide →
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.
To specify that a prop should be merged, you can use the merge
method on the prop value.
Route::get('/users', function () {
$page = request()->input('page', 1);
$per_page = request()->input('per_page', 10);
return Inertia::render('Users/Index', [
'results' => Inertia::merge(User::paginate($page, $per_page)),
]);
});
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.
You can also combine deferred props with mergeable props to defer the loading of the prop and ultimately mark it as mergeable once it's loaded.
Route::get('/users', function () {
$page = request()->input('page', 1);
$per_page = request()->input('per_page', 10);
return Inertia::render('Users/Index', [
'results' => Inertia::defer(fn() => User::paginate($page, $per_page))->merge(),
]);
});
On the client side, you can indicate to the server that you would like to reset the prop. This is useful when you want to clear the prop value before merging new data, such as when the user enters a new search query on a paginated list.
The reset
request option accepts an array of the props keys you would like to reset.
router.reload({
reset: ['results'],
//...
})