Skip to content

Instantly share code, notes, and snippets.

@khola khola/useQuery.js
Created May 10, 2019

Embed
What would you like to do?
import { useEffect, useState } from "react";
import { API, graphqlOperation } from "aws-amplify";
import * as queries from "../queries";
export const useQuery = query => {
const [loading, setLoading] = useState(true);
const [data, setData] = useState(null);
const getFromAPI = async () => {
const users = await API.graphql(graphqlOperation(queries[query]));
setData(users.data[query].items);
setLoading(false);
};
useEffect(() => {
getFromAPI();
}, []);
return [data, loading, getFromAPI];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.