From the course: Building a GraphQL Project with React.js

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Generating state

Generating state

- [Instructor] So now we need to find a way of creating the variable that we need, so that we can access it in our application. So in this component, we want to go ahead and print out the name of the user. Now to do that, we're going to to have to use another hook called useState. So if you remember from previous versions of react you could define a variable called state that you could access in your applications. The way that this works with hooks is by allowing you to use another feature called the useState. So you call it into the component that you want to use that state with and then you get the ability to create a variable. So here, I'm going to say, let and I'm going to create a variable called userName. And then I'm going to also have the ability of setting the value of that variable with a function. So, this user effect is going to give you access to creating these two functions. So userName here, and that is…

Contents