Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thetanaz's avatar

Need help implementing Inertia V2's infinite scroll with React

So I was ecstatic when I heard about the new way to implement infinite scrolling with Inertia 2.0 and decided to give it a test, so I made a quick project following their docs and now I don't understand how to use The new <WhenVisible> component to load more "articles".

This is the controller, implementing basic pagination and the new merge functionality:

class ArticleController extends Controller
{
    public function index(Request $request)
    {
        $page = $request->input('page', 1);
        $perPage = $request->input('per_page', 15);

        $articles = Article::orderBy('created_at', 'desc')
            ->paginate($perPage, ['*'], 'page', $page);

        return Inertia::render('Articles', [
            'articles' => Inertia::merge(fn() => $articles),
        ]);
    }
}

And this is the react component, in short I have no idea how to use the WhenVisible component to keep rendering, as you can see now I have a <p className="text-center text-gray-500">Loading more...</p> inside it which is clearly wrong, I tried having an empty div there, obviously doesn't work, I also tried wrapping the main div of the return statement in the WhenVisible component but that doesn't work because WhenVisible expects a string? inside it for some reason. I'm preplexed as to how do I use this new WhenVisible component, and the few tutorials I found were with VUE, anyone care to explain?

0 likes
2 replies
deviceafraid's avatar

Hello anam, I have used your package. I feel this new package is quite stable, if I find any errors I will notify you solar smash online

Please or to participate in this conversation.