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:

debugging javascript web apps

How to master JavaScript debugging for web apps

With the right tools and strategies, JavaScript debugging can become much easier. Explore eight strategies for effective JavaScript debugging, including source maps and other techniques using Chrome DevTools.

Ivy Walobwa
Jan 9, 2025 ⋅ 8 min read
A Deep Dive Into Angular’s FormArray Container

A deep dive into Angular’s FormArray container

This Angular guide demonstrates how to create a pseudo-spreadsheet application with reactive forms using the `FormArray` container.

Kayode Adeniyi
Jan 8, 2025 ⋅ 3 min read
Handling React Loading States With React Loading Skeleton

Handling React loading states with React Loading Skeleton

Implement a loading state, or loading skeleton, in React with and without external dependencies like the React Loading Skeleton package.

Ibadehin Mojeed
Jan 7, 2025 ⋅ 7 min read
Getting Ready For Tailwind V4.0

Getting ready for Tailwind v4.0

The beta version of Tailwind CSS v4.0 was released a few months ago. Explore the new developments and how Tailwind makes the build process faster and simpler.

Oscar Jite-Orimiono
Jan 6, 2025 ⋅ 12 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