Skip to content

Instantly share code, notes, and snippets.

@nikolasburk
Last active June 9, 2017 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikolasburk/bc4bbfbac20d724a3ffdeff32cc3747a to your computer and use it in GitHub Desktop.
Save nikolasburk/bc4bbfbac20d724a3ffdeff32cc3747a to your computer and use it in GitHub Desktop.
const NewPostsSubscription = gql`
subscription {
Post(filter: {
mutation_in: [CREATED]
}) {
node {
id
imageUrl
description
}
}
}`
class ListPage extends React.Component {
// ...
componentDidMount() {
this.subscription = this.props.data.subscribeToMore({
document: NewPostsSubscription,
updateQuery: (previousState, {subscriptionData}) => {
const newPost = subscriptionData.data.Post.node
return {
allPosts: [
{...newPost},
...previousState.allPosts
]
}
},
onError: (err) => console.error(err),
})
}
// ...
}
@t0wer001
Copy link

t0wer001 commented Jun 9, 2017

Hi, I'm getting a compile error:

error 'newProps' is not defined no-undef

I was wondering where the newProps should be defined?

@nikolasburk
Copy link
Author

Hey @AntonBramsen! Sorry this is a typo. It should be this.props.data.subscribeToMore({...}). Will fix it right away, thanks for the hint!! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment