Welcome to the Treehouse Community
Looking to learn something new?
React + Express REST API - Best Method for handling sorting/filtering of data?
I'm able to retrieve data from the API using axios and display it on page using React. All good so far. Sorting and filtering has me a bit stumped at the moment. To sort and filter the data on page should I be looking to do that by constucting UI components that update GET request parameters , or avoid another API call and use React to do the sorting and filtering?
Ken AlgerTreehouse Teacher
I would say that, as with many things in software development, it depends. I can see a situation in which using React to handle the filtering would work. I can also see situations in which designing the database query to allow for the database to do the filtering and sorting would be beneficial.
I think knowing more about your specific application and data flow for searching, filtering, and reporting would be necessary before providing a nudge in a particular direction would be necessary.
Thanks for taking the time to reply Ken.
FWIW I decided to go with the database query approach this time, seeing as the app is more data driven and I'm the one building the API I can tailor endpoints to suit, with added bonus of flexibility enough that the sort and filter function aren't tied to React in the case I want a different display solution in future, cheers!