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:

JavaScript Dictionary

JavaScript dictionary: How to use objects and maps for key-value pairs

Learn how to use JavaScript dictionaries with Objects and Maps. Discover key differences, performance insights, and best use cases with practical examples.

Elijah Agbonze
Feb 25, 2025 ⋅ 9 min read
A guide to the CSS grid-template-columns property

A guide to the CSS grid-template-columns property

Take a deep dive into the CSS grid template columns property, an essential part of the CSS Grid Layout specification.

Samuel Martins
Feb 25, 2025 ⋅ 15 min read
A Guide To Node.js Readable Streams

A guide to Node.js readable streams

Explore how Node.js readable streams process data in small chunks, manage data flow, handle errors, and ensure resource cleanup.

Yan Sun
Feb 25, 2025 ⋅ 7 min read
Advanced React State Management Using URL Parameters

Advanced React state management using URL parameters

Manage state in React using URL parameters for better performance, SEO, and accessibility while enabling shareable and server-rendered application states.

Rahul Chhodde
Feb 24, 2025 ⋅ 16 min read
View all posts

5 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