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 trialhum4n01d
25,493 PointsBetter way to handle start/stop
This is just my opinion, but isn’t this the best way to implement the start/stop text?
<button>{this.state.running ? "Stop" : "Start"}</button>
It’s similar to what @jim did, but it doesn’t have the duplicate <button>
code.
My question is, did I make a mistake?
2 Answers
Adam Fields
Full Stack JavaScript Techdegree Graduate 37,838 PointsYou had the right idea!
For your button onClick
, use this:
handleClick () {
this.setState({ running: !this.state.running });
}
I know you wrote this 5 months ago, but perhaps other students will see it.
hum4n01d
25,493 PointsWell never mind, as I kept watching the video, I realized that it would be hard to implement the click handlers this way. :D
Gabbie Metheny
33,778 PointsGabbie Metheny
33,778 PointsThis worked great, thanks Adam!
Mark Wowor
Front End Web Development Techdegree Student 14,630 PointsMark Wowor
Front End Web Development Techdegree Student 14,630 PointsYeah. It worked well.