Next.js Discord

Discord Forum

Adding URL parameters using new state value after useState is called

Unanswered
Siberian Flycatcher posted this in #help-forum
Open in Discord
Siberian FlycatcherOP
I have tried to figure out how to update the url parameters after a state function and simply can't get it working. Do you know how I could dynamically set the name of the selected RadioGroup.Option as a url params?

12 Replies

@Siberian Flycatcher I have tried to figure out how to update the url parameters after a state function and simply can't get it working. Do you know how I could dynamically set the name of the selected RadioGroup.Option as a url params?
do you just want it updated client side? or do you want to want to actually use the searchParams to define the state. there is no point in having both
Siberian FlycatcherOP
Well i am writing this for an addToCart function for swell.is e-commerce integration that reads the url parameters when the "Add to cart" button is clicked.
When i use the useSearchParams and useRouter method the page flickers. Seems like there should be a clean way to pull this off.
the page flickers where
in dev?
Siberian FlycatcherOP
Yes.
thats because its dev
you reload everything every request and render 2x
those and making the mistake to use css-in-js like mui are the only things that cause page flickers.
if the only thing you are doing is setting a searchParam, that entire component has no use to be a client component. A form with a severAction is a great use case for this specific circumstance.
Siberian FlycatcherOP
Okay. I will try that instead. Thanks for the feedback!