Skip to content
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

Incorrect and insufficient documentation related to implementing merging props in laravel 11 + Inertia js + React #389

Open
mani-hash opened this issue Feb 1, 2025 · 0 comments

Comments

@mani-hash
Copy link

Description

The documentation in Merging props is incorrect for server side implementation and also contains insufficient documentation for client side implementation (in react)

Software Info

  • Laravel 11
  • Inertia Js 2
  • React 18.3 (typescript)

Incorrect Code

Here are the 2 types of laravel code given for implementing merging props

  • Without defer props
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)),
    ]);
});
  • With Defer props
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(),
    ]);
});

The main problem with the above code is incorrect use of paginate() method! Paginate only accepts one argument and it is the $per_page argument. Passing 2 is incorrect and results in an error.

Insufficient documentation

The documentation is not clear on how to actually use the merged props partly due to the above incorrect code and secondly due to not enough documentation for react especially when handling defered props

Here is the code from website

import { Deferred } from '@inertiajs/react'

export default () => (
    <Deferred data="permissions" fallback={<div>Loading...</div>}>
        <PermissionsChildComponent />
    </Deferred>
)

This is unclear and does not really help anyone reading documentation. Improved documentation would be something like this:

Improved version

import { Deferred } from '@inertiajs/react'

function PermissionsChildComponent() {
    const { permissions } = usePage().props;
    return (
        <div>
            {permissions && permissions.type}
        </div>
    );
}

export default () => (
    <Deferred data="permissions" fallback={<div>Loading...</div>}>
        <PermissionsChildComponent />
    </Deferred>
)

Tldr

Unable to implement merged props in laravel + inertia js + react webapp due to incorrect and insufficient documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant