Issue building a search component
Answered
Rhinelander posted this in #help-forum
RhinelanderOP
So I am currently trying to implement a feature in my web application where a user can enter some text in a text field and then I use that text entered from that user to fetch information about what they entered, the issue I am running into is I need use a client component to handle the text state changing pass and then fetch data using an api about the text that the user entered. I cannot have a server component inside a client component directly so how could I fetch the data in the client component? Would using an API route be the best approach?
38 Replies
have search text on query params
and search input on a different client component
Answer
RhinelanderOP
sorry im still trying to learn everything but your passing the query to a client component and using routing to send the user to another page?
not another page, same page
but adding search query to it
I've pagination code cause I've pagination too
but I suppose you won't need it
RhinelanderOP
I see
can you explain where you are getting the query from one users function?
I see where you are initializing it and assigning it to searchparams
but im not sure what that is
you automatically get searchParams as props in a page
RhinelanderOP
so your getting the query from the url and passing it as a prop to your CustomSearchBar component?
RhinelanderOP
okay so how is the url being updated from the query?
idk if I asked that in the right way
RhinelanderOP
oh I see
thank you
your updating it whenever the form is submited
RhinelanderOP
okay very cool
thank you for your help
no problem, if your problem is solved, consider marking answer as solution
RhinelanderOP
gotcha
RhinelanderOP
oh my bad
RhinelanderOP
appreciate you