In this lesson, you will learn how to use variables to update local state in React with your Apollo Link State Mutations.
Instructor: To add a variable to our mutation, we need to start by updating our GQL. I'm going to add parentheses and then give the variable a name. I'm going to call it amount. Then we have to specify the data type, which is int. It's required.
I can pass the amount into the mutation. I'm going to say amount is equal to my variable called amount. This amount, I need to pass in when I call the increment mutation. We're calling it right here.
I'm going to say onclick. We're going to call increment. I need to pass in variables. The variable I need to pass in is this amount. I'm going to say amount is equal to two.
I can use this amount in my mutation up here. It's going to be the second parameter. I called it amount. Now I can use that in the actual data that I write.
When I save this, I can click the plus. We're incrementing by two. I can change this to anything I want to. Let's do four. Now we increment by four.
You must be a Pro Member to view code
Access all courses and lessons, track your progress, gain confidence and expertise.