Skip to content

Instantly share code, notes, and snippets.

@jaunesarmiento
Created August 1, 2020 14:00
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 jaunesarmiento/951282c65fd94cddb8685177f93d6a8d to your computer and use it in GitHub Desktop.
Save jaunesarmiento/951282c65fd94cddb8685177f93d6a8d to your computer and use it in GitHub Desktop.
// useEffect(..., []);
useEffect(() => {
const subscription = API
.graphql(graphqlOperation(onCreateMessage))
.subscribe({
next: (event) => {
setMessages([...messages, event.value.data.onCreateMessage]);
}
});
return () => {
subscription.unsubscribe();
};
}, [messages]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment