Dynamically Update Local State using Apollo Link State with Mutation Variables

Ben Awad
InstructorBen Awad
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 years ago

In this lesson, you will learn how to use variables to update local state in React with your Apollo Link State Mutations.

Instructor: [00:01] 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.

[00:15] 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.

[00:27] 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.

[00:40] 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.

[00:52] 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.

egghead
egghead
~ 42 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today