-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch Sidebar to Client Component + useSearchParams? #1
Comments
Ok but now what if i need the data of the sidebar fetched on the server...? |
Not really related to my issue above I guess. But as a note, data can be fetched on the server and passed to Client Components. |
How can i fetch the right data if i need the path and searchParams that are not available in the server component (server component that arent inside the page, totally related to your case, its the whole point.) except that you choose to fetch data client side, thats not a solution as it defeat the whole purpose of next js. |
For example, fetch the nav data in the Server Component (eg. Lots of different patterns to fetch + pass data from Server Components to Client Components, which is why I said that it's unrelated to usage of a hook. |
I don't really know how to formulate it otherwise: i need the pathname and searchparams to fetch the data in the first place. The Layout doesnt have this, and doesn't allow for useParams or useSearchParams because its a server component. |
Understood, I didn't get that point so far. It's still not related to my issue above. But there are options for this pattern too, including using nested layouts and route segments. The nested layout receives the route segment details. Reading through all of the comments in this issue may be helpful: |
Ok, well its totally related to your issue because its basically the same issue, the only difference is that you were good by just switching the sidebar to client component. Thanks for your link i will check into that. But in the meantime i found a solution to get the params and search params via middleware: `// middleware.ts // the following code is taken from : https://nextjs.org/docs/advanced-features/middleware#setting-headers return NextResponse.next({ // the following code has been copied from https://nextjs.org/docs/advanced-features/middleware#matcher |
Hi @chantastic ! First of all, thanks so much for providing the React Holiday content, really amazing to learn Next.js 13!
I wanted to follow up on issue 20: "I've made a huge mistake...", in which you detail that layouts do not receive
searchParams
.It seems that this is true, and may be by design:
searchParams
asprops
vercel/next.js#43863However, there is a workaround - convert the sidebar (the
<aside>
) to a client component and use theuseSearchParams
hook fromnext/navigation
in this client component, also explained here:searchParams
asprops
vercel/next.js#43863 (comment)Would you consider refactoring your commit where you use
new URLSearchParams()
to use this client component + hook approach instead?The text was updated successfully, but these errors were encountered: