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 Basics (2018) Understanding State Understanding State Review

Value 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.

Zack Jackson
Zack Jackson
30,220 Points

Put a line of three backticks before and after your code in the forum to format it.

Then it will look like this:

your code

5 Answers

Zack Jackson
Zack Jackson
30,220 Points

Since 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.

This 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?

I 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
Zack Jackson
30,220 Points

Ewen 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.

Thanks Zach Johnson

Thanks!

Thanks for clear question.