Data fetching best practices
Answered
Himalayan posted this in #help-forum
HimalayanOP
I am currently building a form that uses user inputs to fetch & filter data based on those inputs, using a server actions seems a bit weird (using a POST method for what is essentially a GET method) and from what i've been reading in docs and seen in videos, using the api route handlers isn't the best practice, so I am a bit confused as to what is considered the best practice to fetch data with user inputs and a submit button
Answered by joulev
A good practice is by search params. Something like /search?q=hello+world. You can then get the data in the page server component
4 Replies
@Himalayan I am currently building a form that uses user inputs to fetch & filter data based on those inputs, using a server actions seems a bit weird (using a POST method for what is essentially a GET method) and from what i've been reading in docs and seen in videos, using the api route handlers isn't the best practice, so I am a bit confused as to what is considered the best practice to fetch data with user inputs and a submit button
A good practice is by search params. Something like /search?q=hello+world. You can then get the data in the page server component
Answer
@joulev A good practice is by search params. Something like /search?q=hello+world. You can then get the data in the page server component
HimalayanOP
Wouldn't that reload the page since I would ideally start on the search page, enter the inputs values and then submit to get the data?
@James4u https://nuqs.47ng.com/
<@226014292787331080> this library should be good for you
HimalayanOP
Currently reading 🙂