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!

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


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
228,039 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