Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


React + Express REST API - Best Method for handling sorting/filtering of data?

Recently finished the full stack Javascript track and am now playing with React. I am working on a test project using Express API + MongoDB server side, and React on Client side.

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?

2 Answers

Ken Alger
Ken Alger
Treehouse 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.

Happy coding,

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!