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 React Components (2018) React Component Patterns Destructuring Props

1 Answer

Tyler McDonald
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tyler McDonald
Full Stack JavaScript Techdegree Graduate 16,700 Points

Within a class Component, the render() method is what actually reads or examines the props. If you try to destructure props outside of the render() method, it won't work because our class Component doesn't have access to the props outside of render().

However, when we destructure within render(), we are actually using the props parameter passed in from whichever component passed the props.

There is some React "magic" going on here (really it's just React abstracting away the code that takes care of passing around props), which is why we don't actually see the props passed to render() like we do in a functional Component.