Next.js Discord

Discord Forum

set searchParams in actions

Answered
Chausie posted this in #help-forum
Open in Discord
ChausieOP
I need to set searchParams in server actions and I saw a lot of people asking for the same so it is obviously needed, is it possible and if yes how? If not why not?
Answered by B33fb0n3
please mark solution
View full answer

6 Replies

you can set them by redirecting the client to it. And yes you need a client, because a server actions runs on the server and the server don't know states. So return for example the redirect url (with the searchparams) and after your server actions is complete redirect the client to the new url @Chausie
no idea without seeing the code :this_is_fine:
ChausieOP
usually in previous projects I got searchParams sugguested by the next envoirment, but now in this one not.
export default function Home({ searchParams }: any) {
 //...
}
I do not really know what type it is.
try it like this:
export default function Home({
  searchParams,
}: {
  searchParams: { [key: string]: string | string[] | undefined }
}) {
 // ...
}
please mark solution
Answer