Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Dabit committed Apr 25, 2019
1 parent 75d4393 commit d1bf316
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,19 +580,28 @@ To do so, we need to define the subscription, listen for the subscription, & upd
// import the subscription
import { onCreatePet as OnCreatePet } from './graphql/subscriptions'

// define the subscription in the class
subscription = {}

// subscribe in componentDidMount
API.graphql(
graphqlOperation(OnCreatePet)
).subscribe({
next: (eventData) => {
console.log('eventData', eventData)
const pet = eventData.value.data.onCreatePet
if (pet.clientId === CLIENT_ID) return

const pets = [ ...this.state.pets, pet]
this.setState({ pets })
}
});
componentDidMount() {
this.subscription = API.graphql(
graphqlOperation(OnCreatePet)
).subscribe({
next: (eventData) => {
console.log('eventData', eventData)
const pet = eventData.value.data.onCreatePet
if (pet.clientId === CLIENT_ID) return

const pets = [ ...this.state.pets, pet]
this.setState({ pets })
}
})
}

componentWillUnmount() {
this.subscription.unsubscribe()
}
```

### Adding Authorization to the GraphQL API (Advanced, optional)
Expand Down

0 comments on commit d1bf316

Please sign in to comment.