2022-09-09
1309
#react
John Reilly
131517
Sep 9, 2022 ⋅ 4 min read

useState with URLs: How to persist state with useSearchParams

John Reilly MacGyver turned Dev 🌻❤️ TypeScript / ts-loader / fork-ts-checker-webpack-plugin / DefinitelyTyped: The Movie

Recent posts:

Radix Ui Adoption Guide Overview Examples And Alternatives

Radix UI adoption guide: Overview, examples, and alternatives

Radix UI is quickly rising in popularity and has become an excellent go-to solution for building modern design systems and websites.

Nefe Emadamerho-Atori
Apr 25, 2024 ⋅ 11 min read
Understanding The Css Revert Layer Keyword, Part Of Css Cascade Layers

Understanding the CSS revert-layer keyword

In this article, we’ll explore CSS cascade layers — and, specifically, the revert-layer keyword — to help you refine your styling strategy.

Chimezie Innocent
Apr 24, 2024 ⋅ 6 min read
Exploring Nushell, A Rust Powered, Cross Platform Shell

Exploring Nushell, a Rust-powered, cross-platform shell

Nushell is a modern, performant, extensible shell built with Rust. Explore its pros, cons, and how to install and get started with it.

Oduah Chigozie
Apr 23, 2024 ⋅ 6 min read
Exploring Zed, A Newly Open Source Code Editor Written In Rust

Exploring Zed, an open source code editor written in Rust

The Zed code editor sets itself apart with its lightning-fast performance and cutting-edge collaborative features.

Nefe Emadamerho-Atori
Apr 22, 2024 ⋅ 7 min read
View all posts

4 Replies to "<code>useState</code> with URLs: How to persist state with <code>useSearchParams</code>"

  1. You can update search params easily with this approach, using native useSearchParams functional update.

    setSearchParams((searchParams) => {
    searchParams.set(“greeting”, “hi”);
    return searchParams;
    });

  2. Hi,

    Great post!
    It would be nice to see a section on how to manage updating multiple keys at the same time.
    For example if you set State A then State B you will end up with only State B’s changes.

    In my case I am trying to update a start and end date that are updated by the same callback function.

    Cheers,
    Casey

Leave a Reply