News for hackers. Stuff that matters.
Re:Htmx and URL State Management by cadamsdotcom on Tuesday July 29, 2025 @07:39PM (#44729487)
This pattern - saving the query to the URL with the history API - is fantastic UX but never gets implemented because there’s never time. Luckily an LLM can build this quickly as it’s straightforward and mostly boilerplate.

Still the boilerplate makes me wonder if it belongs in a library, eg. a React hook that’s a drop in replacement for `useState`. Backend logic would still need to be implemented. Does something like this exist?

Re:Htmx and URL State Management by monadoid on Tuesday July 29, 2025 @07:43PM (#44729518)
Agreed I love this pattern! I'm a big fan of using nuqs for this in nextjs, but really stoked to try out rust / loco / htmx for my next project.
Re:Htmx and URL State Management by PaulHoule on Tuesday July 29, 2025 @08:26PM (#44729793)
Doesn't react-router do something like this?
Re:Htmx and URL State Management by nosefurhairdo on Tuesday July 29, 2025 @08:34PM (#44729841)
Yep, `useSearchParams()`. At work I built a wrapper to incorporate zod schemas for typesafe search param state. Nuqs is the best for this if your application meets its prerequisites: https://nuqs.47ng.com/
Re:Htmx and URL State Management by t-writescode on Tuesday July 29, 2025 @08:35PM (#44729845)
> is fantastic UX but never gets implemented because there’s never time

Wouldn't the change take something like an hour the first time you implement it and then 10s of seconds for calling the centralized function henceforth?

I don't think the problem is "there's never time"; and if that is the problem, I don't think an LLM will "solve" that, especially since studies have shown developers are slower when they use LLMs to code for them.

Re:Htmx and URL State Management by crab_galaxy on Tuesday July 29, 2025 @09:14PM (#44730073)
> never gets implemented because there’s never time

In my experience that time is saved and more when you find you no longer need to manage Zustand/redux stores to track application state. This pattern works beautifully when incorporating the query parameters as query keys with tan stack query too.

Re:Htmx and URL State Management by c-hendricks on Tuesday July 29, 2025 @09:37PM (#44730186)
At work we have a hook for that with various backends (memory, local storage, redux, and search params). Supports page, offset, and cursor pagination.

https://stackblitz.com/edit/github-8ssor8-rqkyew8w?file=src%...

Re:Htmx and URL State Management by franky47 on Wednesday July 30, 2025 @02:50AM (#44731487)
> Still the boilerplate makes me wonder if it belongs in a library, eg. a React hook that’s a drop in replacement for `useState`

That’s exactly what `nuqs` does (disclaimer: I’m the author).

> Backend logic would still need to be implemented

Assuming your backend is written in TypeScript, you can use nuqs loaders to reuse the same validation logic on both sides.

https://nuqs.47ng.com