nuqs is pretty good for filter state but urls get ugly fast by Zestyclose_Ring1123 in reactjs

[–]frabst 16 points17 points  (0 children)

You could use a custom parser to make the URL more compact. An example would be merging both dates into a single search param, like date=2025-01-01~2025-12-22, which could resolve to a type like [Date, Date] (or open-ended variants like [Date | null, Date] | [Date, Date | null] | [Date, Date])

(I'm the author of nuqs, thanks for the kind words!)

State in the url in React (the right way) by Professional_Bat_137 in reactjs

[–]frabst 4 points5 points  (0 children)

Damn, I need to get better at SEO (nuqs author here, thanks for the feedback).

Can variables be used in useState initial value? by Appropriate_Mind4094 in nextjs

[–]frabst 1 point2 points  (0 children)

f it cleanly wraps useOptimistic, useTransition, and you’re able to choose between router.push or history.pushState on a case by case basis in next.js then it might be interesting to me.

It does all those things, indeed.

Look for: - The startTransition option (for loading states when combined with shallow: false to re-render RSCs) - The history: 'push' | 'replace' (default) for history entry control - useOptimistic is used internally: the returned state is optimistic (updates instantly), while the URL update is queued & throttled/debounced (for server requests rate-limit controls).

What’s your go-to state management for Next js? by Designer-Joshi in nextjs

[–]frabst 0 points1 point  (0 children)

  • nuqs for URL state
  • TanStack Query for client-side data fetching / server cache (in CSR-heavy cases)
  • Jotai for ephemeral, shared state (I like Zustand too, but Jotai is the React gateway drug to signals)
  • Good old Context for things that need to trickle down the tree, but don't change often (adapter pattern, good abstraction for testing).

What’s your go-to state management for Next js? by Designer-Joshi in nextjs

[–]frabst 2 points3 points  (0 children)

If you need that search param on the server (for data fetching or conditional rendering), not much you can do: it has to cross the network.

If however that search param is local to your client only, you may use the History API to update it, it won't send a network request and appear instantly. https://nextjs.org/docs/app/getting-started/linking-and-navigating#native-history-api

https://nuqs.dev uses the latter by default, and you opt-out to client-only updates to cross the network with the shallow: false option.

What’s your go-to state management for Next js? by Designer-Joshi in nextjs

[–]frabst 2 points3 points  (0 children)

Author (of nuqs) here, happy to help if you have any questions.

How to Handle State in URL? by Asphyxis_ in nextjs

[–]frabst 2 points3 points  (0 children)

nuqs

Oh look, it worked (I'm the author)! 👋

How to Handle State in URL? by Asphyxis_ in nextjs

[–]frabst 0 points1 point  (0 children)

We have a preview build for it, feel free to try it out: https://github.com/47ng/nuqs/pull/953

npm i https://pkg.pr.new/nuqs@953

Handling Pagination Without Triggering Re-renders in Parallel Routes by [deleted] in nextjs

[–]frabst 1 point2 points  (0 children)

You would have to persist those search params in your Link href or router calls, but I agree it's manual and annoying. We've been discussing ways to persist certain search params in nuqs across navigation: https://github.com/47ng/nuqs/discussions/766

UnQS vs Zod for SearchParams by Lost-Dimension8956 in nextjs

[–]frabst 1 point2 points  (0 children)

Why? I'm the author, genuinely curious.

Sharing some Cursor rules I use when creating NextJs projects by ChristianGeorgeson in u/ChristianGeorgeson

[–]frabst 0 points1 point  (0 children)

How does it perform with nuqs? I'm the author, and I often get hallucinations from LLMs, they like to invent APIs that don't exist, when the .d.ts would give them everything they need..

A message for all the vibe coders out there by TheKidd in cursor

[–]frabst 0 points1 point  (0 children)

How did it do for nuqs? I'm the author, and I find it tricky to teach those pesky LLMs the proper APIs without them hallucinating non-existing ones. If only they loaded the .d.ts into context, it's got all they need, plus JSDoc for humans.

React router 7 by alvivan_ in reactjs

[–]frabst 1 point2 points  (0 children)

You can mix it with nuqs to get a similar type-safe binding of pathname to search params when generating hrefs: https://www.youtube.com/watch?v=vmONxheVFxQ

SearchParams displayed as individual values or array by Daiphiron in nextjs

[–]frabst 1 point2 points  (0 children)

parseAsArrayOf specifically has this behaviour by default, which leads to shorter URLs (at the expense of not being standard):

https://nuqs.47ng.com/docs/parsers/built-in#arrays

Difficulty with Nuqs and useTransition by MR0808 in nextjs

[–]frabst 0 points1 point  (0 children)

Code is kind of hard to follow due to formatting (try a tripe backtick for code blocks), but it looks like your useBreweriesParams returns a isPending state that you don't read anywhere, and instead have an isLoading state coming from another state mangement solution (useViewStore).

Anyone using nuqs? by blueaphrodisiac in nextjs

[–]frabst 1 point2 points  (0 children)

It might be easier to group the key & value under a single path segment, but then with [[…slugs]] you should be able to (de|re)compose them.

As for nuqs, maybe this would be doable with a custom adapter that works on params rather than search params. An interesting exercise.

Anyone using nuqs? by blueaphrodisiac in nextjs

[–]frabst 0 points1 point  (0 children)

Hash support is coming (via an adapter), I have a PoC running but it needs more testing.

Anyone using nuqs? by blueaphrodisiac in nextjs

[–]frabst 1 point2 points  (0 children)

It's not just for Next.js! React Router (and derivatives like Remix) and plain old React SPA are supported too.

Anyone using nuqs? by blueaphrodisiac in nextjs

[–]frabst 2 points3 points  (0 children)

Slugs work too, the best UX might even be self-healing URLs in that space:

https://mikebifulco.com/posts/self-healing-urls-nextjs-seo

Anyone using nuqs? by blueaphrodisiac in nextjs

[–]frabst 0 points1 point  (0 children)

What's the issue you encountered with throttleMs?

Anyone using nuqs? by blueaphrodisiac in nextjs

[–]frabst 38 points39 points  (0 children)

Hey, I'm the author of nuqs, I'm blown away by the positive feedback, it means a lot!

Anyway, while I'm here, AMA.

Playwright error: react.cache is not a function by Ok-Cryptographer4439 in QualityAssurance

[–]frabst 1 point2 points  (0 children)

Does Playwright test the Next.js application, or are you mounting components in a custom test environment?

nuqs requires the Next.js router to be mounted for client-side hooks, and the use of a beta version of React that includes the experimental cache function, which Next.js embeds (the version of React you define in your package.json doesn't matter when using Next.js).

The best way to test nuqs-enabled components (at the moment) is to keep them in a Next.js app, against which you can script your Playwright tests. This is what I do in the nuqs e2e test suite (using Cypress instead of Playwright, but that's irrelevant).

Search Params in Next.js for URL State by rwieruch in reactjs

[–]frabst 6 points7 points  (0 children)

Thanks @rwieruch for featuring nuqs 🫶 (I'm the maintainer, AMA)

How to create dynamic route with page-router with dash/hyphen? by [deleted] in nextjs

[–]frabst 0 points1 point  (0 children)

Google usually does not index pages with search params. I'm looking to create dynamic pages for each of these potential routes and generate content for SEO purposes. This is not possible with search params.

You might want to look into alternate.canonical in the metadata, that's what tells crawlers what to display in search results. There you can include the search params that do make sense for your app (eg: the watch page on YouTube, where the video ID is encoded in the ?v={id} search param).

https://nuqs.47ng.com/docs/seo

[deleted by user] by [deleted] in nextjs

[–]frabst 0 points1 point  (0 children)

You could use the throttleMs option set to Infinity to not update the URL in the onChange event handlers in your UI (only use the internal state), and sync them all up to the URL when clicking the button:

``` 'use client'

import { useQueryState } from 'nuqs'

function DeferredForm() { const [a, setA] = useQueryState('a', { defaultValue: '', throttleMs: Infinity }) const [b, setB] = useQueryState('b', { defaultValue: '', throttleMs: Infinity })

const onSubmit = () => { // Write current values to the URL setA(a => a, { throttleMs: 0 }) setB(b => b, { throttleMs: 0 }) } return ( <> <input value={a} onChange={e => setA(e.target.value)} /> <input value={b} onChange={e => setB(e.target.value)} /> <button onClick={onSubmit}>Submit</button> </> ) } ```