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

JavaScript

Brandon Benefield
Brandon Benefield
7,739 Points

Calling props in React

https://teamtreehouse.com/library/passing-data-to-components-via-routes

In this video, we create a CourseContainer component, CourseContainer.js, to replace the HTML, CSS and JS components and use it to render which course we want to view. Now to my understanding, in order to call the props argument, you need to create a COMPONENTNAME.propTypes object. Only in this video, there is no propTypes object to be called from and yet the app is still working.

I'm not sure why this is. My only assumption is that It's connected somewhere but I can't figure that one out.

1 Answer

Ari Misha
Ari Misha
19,323 Points

Hiya there! Data Flow in React is unidirectional and thats the whole point of using React. Now lets just say you passed some data to the parent component so in order to access that data in children functions/components, the only way is pass it through props. Now the thing is the children doesnt need know the datatypes or proptypes. Isnt that how you do it in React?

~ Ari

Brandon Benefield
Brandon Benefield
7,739 Points

I did not realize that's how we were supposed to be passing around data in React. So if children do not need to be aware of the data, and as long as you store the data somewhere and pass it to the parent. When would I need to create a ComponentName.propTypes = {} sort of object?

Ari Misha
Ari Misha
19,323 Points

Lets just say you are passing something every specific like size props. And you need it to be integer and isRequired , then you might wanna consider passin' in props. Ofcourse its not necessary. That being said, it also makes your code complex with regarding to another human sets of eyes. So you might wanna pass propTypes only when it needed to passed something specific. But i kinda use Redux for all my state and data which you'll be studying later. When you'll be progressing trough the courses, it'll all come together for ya. i can defo tell you that. (: