Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Should each React component be responsible for making the API calls for the data it requires?

I'm building out a ReactJS app that will have its data provided via a RESTful API.

Should I have a single API call when the app mounts that indicates which components should load as well as provides all data (top links list, sidebar content, page content, etc..) or should the top links component make an API request for the links JSON object, and each other component do the same?

Steven Parker
Steven Parker
215,939 Points

:mailbox_with_mail: Hi, I got your request. But I haven't taken the React courses yet myself (and have no prior experience with it) so I'll have to leave this one for someone else to answer.

1 Answer

Luke Robinson
Luke Robinson
728 Points

Components should be as dumb as possible, so you don't want them making their own API calls. Instead, the top level component for the page should perform the API calls, and pass the relevant data to it's children as props