Skip navigation
URL state is underrated.
0:00 / 1:55

URL state is underrated.

Lee Robinson

@leerob307K followers

Visit on X
4,198 likesDownloadOriginal post

1,114,110 views

URL state is underrated. Here's an example of how we built Next.js commerce with almost zero `useState` calls.

10 Comments

Comments from the original post on X (Twitter)

  • Dominik 🔮's profile picture

    @TkDodo

    @nextjs url state is great, but just setting `defaultValue` on the search input will not work if you use the browser back button. The url will change, the component re-renders and you'll se the correct search result, but the value in the search input is out of sync:

    211 likes

  • Lee Robinson's profile picture

    @leeerob

    @nextjs Fixed! Added a key to the input.

    123 likes

  • Pablo Bermejo's profile picture

    @peibolsang

    @nextjs Am I missing something? I mean, is this new? This has been always the right pattern when you want to preserve state on refresh. Right?

    19 likes

  • John Rush's profile picture

    @johnrushx

    @nextjs That’s actually old good web we’ve been doing back in 2010

    16 likes

  • Tom Lienard's profile picture

    @tomlienard

    @nextjs Don't forget to wrap components that uses `useSearchParams()` in a `Suspense` boundary, otherwise, your whole page might be sent to the client

    14 likes

  • Ethan Niser's profile picture

    @ethanniser

    @nextjs any plans to expose the internal router events for external libraries to tie into search params? was possible in pages, but no longer which is really sad because its super cool

    13 likes

  • Lee Robinson's profile picture

    @leeerob

    @nextjs Have you seen this?

    22 likes

  • Lance Armah-Abraham's profile picture

    @Discoverlance

    @nextjs It's something I thought of using and trying to implement for multi step forms, but it would mean that the already filled in (mostly non sensitive data) will be in the url (for client and server data synchronizations). And that's what I am not sure about in terms of security.

    11 likes

  • Lee Robinson's profile picture

    @leeerob

    @nextjs Here's how I'd recommend handling forms!

    61 likes

  • Will4_U || Damian's profile picture

    @will4_u_

    @nextjs it's 2023, and React developers found out that URL state exists instead of throwing everything into useState that's wild

    9 likes