Skip to content

Instantly share code, notes, and snippets.

@appwiz
Last active October 16, 2018 04:31
Show Gist options
  • Save appwiz/7b9a927081f72509df17f2c041bc1b62 to your computer and use it in GitHub Desktop.
Save appwiz/7b9a927081f72509df17f2c041bc1b62 to your computer and use it in GitHub Desktop.
Voice Commands - ReactApp - List Only
import React, { Component } from 'react';
import './App.css';
import Amplify, { graphqlOperation } from "aws-amplify";
import { Connect } from "aws-amplify-react";
// TODO configure to point to your API
Amplify.configure({
'aws_appsync_region': 'us-west-2',
'aws_appsync_authenticationType': 'API_KEY',
'aws_appsync_graphqlEndpoint': '...',
'aws_appsync_apiKey': '...'
});
// GraphQL query to get list of commands.
const ListColorCommands = `
query listColorCommands {
listColorCommands {
items {
id
timestamp
color
}
}
}
`;
class App extends Component {
render() {
const ListView = ({ commands }) => (
<div>
<h2>All commands</h2>
<ul>
{commands.map(command => <li key={command.id}>[{command.timestamp} {command.id}] {command.color}</li>)}
</ul>
</div>
);
return (
<Connect query={graphqlOperation(ListColorCommands)}>
{({ data: { listColorCommands } }) => (
listColorCommands && <ListView commands={listColorCommands.items} />
)
}
</Connect>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment