Skip to content

Instantly share code, notes, and snippets.

@gtkatakura
Created May 16, 2019 15:23
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 gtkatakura/efe0a25cea95353d30b521a7e4053f16 to your computer and use it in GitHub Desktop.
Save gtkatakura/efe0a25cea95353d30b521a7e4053f16 to your computer and use it in GitHub Desktop.
import { useContext, useState } from 'react';
import { ApolloContext } from 'react-apollo';
import useDeepCompareEffect from 'use-deep-compare-effect';
const useQuery = (query, { variables }) => {
const { client } = useContext(ApolloContext);
const [state, setState] = useState({
loading: true,
});
useDeepCompareEffect(() => {
client.query({ query, variables }).then(setState);
}, [query, variables]);
return state;
};
export default useQuery;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment