DEV Community

Discussion on: Answers to Common Next.js Questions

Collapse
 
pavelee profile image
Paweł Ciosek

great post! 👏

I wonder in a point "Can I Pass Props from a Client Component to a Server Component?", could we say we can pass through URL?

I mean, we do something like this

// update your URL on client side
router.reload(); // refresh RSC components with new URL state
Enter fullscreen mode Exit fullscreen mode
Collapse
 
perssondennis profile image
Dennis Persson

Thanks :)

router.refresh() should work I suppose, since it do refresh Server Components.

Although, I wouldn't recommend it. I would probably rather turn the Server Component into a Client Component and read the URL with useRouter (or pass as prop if they are not needed to be persisted in the URL).

The reason? Because that way, it all is handled automatically. Manually having to refresh the page when URL is changed is error-prone, one day that will likely turn into a bug.

Plus, if you would need to fully refresh your Server Component to get the URL params to it, you are probably better of with a Client Component, performance-wise.