Next.js Discord

Discord Forum

unable to access useSearchParams

Unanswered
Naeemgg posted this in #help-forum
Open in Discord
I'm trying to access page params, my page contains just one client component and all other server components. the page is server side and I'm trying to access it with the only client component. The problem is I'm getting nothing with it.
<ServerComponent/>
<ServerComponent/>
<ServerComponent/>
<ServerComponent/>
<clientComponent/>

"use client"
import {useSearchParams} from "next/navigation"

const clientComponent = ()=>{
const search = useSearchParams()
const data = search.get("data")
return(<h1>{data}</h1>)}

but if I make whole page use client its working fine

3 Replies

useSearchParams is working fine for me, what is the value of search.get("data")?
If your url looks like /page?data=hello, you should be able to receive the data search param with no problem
yep its exactly like that, more precise
/login?data=role&id=randomUserID&email=user@email.com
this is the exact data I'm willing to get