From the course: React.js: Building an Interface

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

The useState Hook and conditional classes

The useState Hook and conditional classes - React.js Tutorial

From the course: React.js: Building an Interface

The useState Hook and conditional classes

- The modern way to work with React projects is to use a feature called Hooks. Hooks allow you to use state and other react features without having to write classes. Let's go ahead and work on creating a toggle in this component called AddAppointment to turn on and off the showing of this form because we don't really need to see that input form unless somebody is ready to add an appointment. So to do that, I'm going to need to import this feature into this component. So I'll have to say 'import' and I'm going to import useState from React, right? And now I'm going to create a state. This component is going to keep track of a variable and I'm going to call this variable called toggleForm. And this is what's going to allow our application to show or hide the rest of the form. So the way that useState works is you create the name of the variable, and then you also create something that modifies that variable. So it's…

Contents