Apollo React Hooks
Query & Mutation
useQuery
will execute on component mount, giving us back the loading, error and data state. Therefore, it is declarativeuseLazyQuery
will execute the query on command. This is perfect to use in events other than component mount, like on button click- To be clear, you could put this in
useEffect
and it would operate similarly touseQuery
, sinceuseEffect
gets run on component mount
- To be clear, you could put this in
useMutation
will return a function that we can execute to perform the mutation
Errors
we need to stringify errors:
console.log('error', JSON.stringify(err, null, 2))
spec: alternatively, we can use apollo-link-error