From the course: React Essential Training
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Toggling state with a button - React.js Tutorial
From the course: React Essential Training
Toggling state with a button
- [Instructor] Right now, our app component is being rendered and when I click on the close restaurant button, that's going to update the state with the new state that I pass into the set status function. But this is kind of a one time thing where we can only click the button once and then any other time I try to click it, we don't see anything happening. So let's make a change to this so that we get the full experience. What we can do is repeat a button if we'd like to. Create a button that's going to set the state to open and we'll set the button text to read open restaurant. Nice, so back to our browser. The restaurant is currently open, that's the initial state as soon as I render. I then can click on close restaurant, open restaurant and have that happen back and forth when I click on each one of those buttons. Now let's take this a step further and actually replace this button. We're going to try to make all of the same stuff happen, but we'll only use one button. We'll set the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.