Accessing the searchParams from the layout without making it 'use client' #54955
Replies: 3 comments 6 replies
-
Go to your nextjs middleware and try something like this: response.headers.set('your value', request.nextUrl.searchParams ||'no value') Then in the component or layout try getting that value you set like this const searchParams = (await headers()).get('yourvalue')|| |
Beta Was this translation helpful? Give feedback.
2 replies
-
Since |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to create an autocomplete component similar to algolia autocomplete but using all the power of react server components, in the way of creating it I base on the searchParams that you can get from a page.tsx so that from my 'use client' input I changed the searchParams with router.push and rendered the items on the server, everything was fine up to there.
The problem came when I wanted to render this Autocomplete component in my root layout to have it in all my pages, since I can't access the searchParams from my layout without doing this 'use client' which in a way ruined my plans since to use my Autocomplete component would have to be added in each of my page.tsx which is not very good.
If you know of a solution to this problem, I would greatly appreciate it.
Beta Was this translation helpful? Give feedback.
All reactions