Urgent.News

What's breaking now, across thousands of outlets.

Tech

My users table reads one pagination contract: paginate(15), withQueryString, and a React pager that trusts meta

The first admin panel I built fetched all users, dumped them into state, and sliced pages client-side. It worked until a client hit 2,000 users and the list page took eleven seconds to load. Server-side pagination isn't hard. The hard part is agreeing on the contract between Laravel and React so neither side improvises. On the backend, the users index is four lines of intent: $users = User ::…

I built my first admin panel by fetching all users and slicing pages on the client side. However, when I hit 2,000 users, loading times increased to eleven seconds. Server-side pagination proved to be less complex, but the challenge lay in establishing a consistent contract between Laravel and React to ensure neither side improvised.

On the backend, I utilized a simple four-line command to fetch users: $users = User :: query () - latest () - paginate ( 15 ) - withQueryString (); return UserResource :: collection ( $users ); paginate(15) handled the heavy lifting, implementing limit, offset, and total count. withQueryString() appended the current query string to the generated links, allowing future filters like search or role to remain unchanged even after a page change. The frontend ignored these links entirely.

My pager read only meta, constructing a fetchUsers function that fetched users based on the current page and updated both users and meta state accordingly. If the backend provided an incomplete response, the pager gracefully defaulted to a single page, maintaining usability. My pager's simplicity consisted of two buttons, Prev and Next, which fetched the next or previous page upon click.

The React side refrained from computing total or per_page values independently, instead relying on the backend's meta data. This approach prevented drift between frontend and backend pagination logic, ensuring users never encountered a non-existent page. The same pagination contract extended to other lists like the dashboard's recent-users list, and I integrated this pattern across all admin panels. The complete implementation can be found in my Laravel + React SaaS Starter Kit at $19 one-time.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

How I built a live halftone portrait in React with just Canvas 2D

My portfolio is set like a newspaper, so my photo couldn't just be a photo. I wanted it to look like a printed halftone: a grid of dots, bigger where the picture is dark and smaller where it's light.

  • Image transformed into low-resolution grid of dots using Canvas 2D API
  • Dot radius determined by sample darkness with applied tone curve
  • Cursor interaction causes dots to swell and recede in a breathing effect

Pushing Beats Polling Explained: Live Poll Trust Above a Handful of Viewers

Short answer: pushing beats polling above a handful of viewers because one state change should not trigger repeated reads for every screen, but treat delivery as an optimization, not as authorization.

  • Pushing poll results, not polling, reduces unnecessary load and scaling issues with more viewers
  • Trust must be established independently of transport layer for untrusted clients
  • Small, immutable poll state snapshots enable reconnects with correct, up-to-date view

Why we stopped retrying on timeout and built reconciliation instead

Early in StareBrain’s action dispatch layer, we had a simple rule: if an action times out, retry it. It felt safe. It felt standard. It was wrong. The problem isn’t the retry.

  • StareBrain's previous rule was to retry actions on timeout, which proved incorrect.
  • New state model tracks Delivery and Acceptance states independently to reconcile ambiguous actions.

More from Saturday 17 October →