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 trialRobert Glover
20,115 PointsValue of prop named time
What is the answer to this question?
class Clock extends React.Component { render() { return ( <span className="stats"> _____ </span> ); } }
I've tried {props.time}, {this.state.time}, among other crazy answers. All I get is "Bummer!"
Please help.
5 Answers
Zack Jackson
30,220 PointsSince you're in a class based component, you have to reference the props with the "this" keyword. Time is a prop. So chain this, props, and the prop name like so: {this.props.time}
The "this" in this case refers to the class of Clock.
Gene Higgins
16,582 PointsThis is kind of a lame question, considering the final code doesn't use this.props
anywhere. Is this something that happened at the beginning of the module, and then was overwritten because you probably won't ever do this?
ewenearle
Full Stack JavaScript Techdegree Graduate 18,744 PointsI don't understand how props is available, seeing as Clock is a class component. Props is not passed in anywhere. Am I missing something here? I thought props was only available when its passed in through a "function" component.. e.g const Clock = (props) => {}
Zack Jackson
30,220 PointsEwen Earle In a react class, props are bound to this with this being the class. You donβt have to pass it in like you would a react function.
ewenearle
Full Stack JavaScript Techdegree Graduate 18,744 PointsThanks Zach Johnson
Robert Glover
20,115 PointsThanks!
Kevin Nguyen
1,317 PointsThanks for clear question.
Zack Jackson
30,220 PointsZack Jackson
30,220 PointsPut a line of three backticks before and after your code in the forum to format it.
Then it will look like this:
your code