Created
May 16, 2019 15:23
-
-
Save gtkatakura/efe0a25cea95353d30b521a7e4053f16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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