Skip to content

Instantly share code, notes, and snippets.

@jaunesarmiento
Last active August 3, 2020 15:56
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/9e4cf946ee39c3cf4b3d54267b8d964b to your computer and use it in GitHub Desktop.
Save jaunesarmiento/9e4cf946ee39c3cf4b3d54267b8d964b to your computer and use it in GitHub Desktop.
const [messageBody, setMessageBody] = useState('');
// useEffect(...) for loading initial messages
// useEffect(...) for subscriptions
const handleChange = (event) => {
setMessageBody(event.target.value);
};
const handleSubmit = async (event) => {
event.preventDefault();
event.stopPropagation();
const input = {
channelID: '1',
author: 'Dave',
body: messageBody.trim()
};
try {
setMessageBody('');
await API.graphql(graphqlOperation(createMessage, { input }))
} catch (error) {
console.warn(error);
}
};
// return (...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment