nextjs13 do get request with searchbar
Hi, I am currently building a nextjs 13 project, trying to get in touch with the app router and server components.
I currently have a searchbar, which is a client component, and I want it to do a get request from an api with the input from the searchbar. Should that request be done in a client component with something like react-query or is there some work around to be able to fetch inside a server component?
6 Replies
do in the server component
use the url to send a search param
https://yoursite.com/something?search=some
I have a page that uses react-table to display some data from the backend. When I search something, I want to do a filtered fetch from my API and load that data in the table. If I do your approach I will be rerendering the whole page everytime I do a search instead of just rerendering the table right? Is that better than fetching data on a client component? Also is that good practice if I have multiple filters?
if you want to use app router and server components
that is what should be done
seems like your case is a client only search
maybe this is a very noobie thing to ask, but how do I know if my case is a client only search or not?
and ty for the help btw
If you have to rely in heavy interactivity, maybe a client component is worth it
Does not mean that you can't use server components
If you want to make a search that the user can add multiple params, before searching, you can use a server component
okay maybe I will try using a server component
thanks!