#I tried to use native interface for

1 messages · Page 1 of 1 (latest)

raven fractal
#

Im not sure where you're getting errors about something being unsafe. You could create your own useSearchParams hook that allows you to mutate params and updates the react state so you could react to those changes in your code.

Such hooks probably exist already

haughty slate
#

Errors come from when I involve History.replaceState(). Is it not the way to do it?

#

The History.replaceState() method modifies the current history entry, replacing it with the state object and URL passed in the method parameters. This method is particularly useful when you want to update the state object or URL of the current history entry in response to some user action.
https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState

raven fractal
#

Shouldnt something like this work?

const p = new URL(location.href);
p.searchParams.append('x', 'y');
history.replaceState({}, '', p.href)
#

Obviously you'd have to figure out then how to update the react state