Created
March 14, 2018 15:55
-
-
Save peggyrayzis/cb40bc9145ef647f21316861f395518e to your computer and use it in GitHub Desktop.
Apollo Link State + React Apollo 2.1 = <3 <3 <3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { ApolloConsumer, Query } from 'react-apollo'; | |
import gql from 'graphql-tag'; | |
const SimpleMutation = () => ( | |
<ApolloConsumer> | |
{(cache) => ( | |
<button onClick={() => cache.writeData({ data: { status: 'yo' }})}>Click me!</button> | |
)} | |
</ApolloConsumer> | |
) | |
// make sure to set an initial value for status in defaults when you initialize link-state | |
const QueryThatSubscribesToMutation = () => ( | |
<Query query={gql`{ status @client }`}> | |
({ data, client }) => ( | |
<div> | |
<p>{data.status}</p> | |
<button onClick={() => client.writeData({ data: { status: 'yo' }})}>Click me!</button> | |
</div> | |
) | |
</Query> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment