Apollo React Hooks
Query & Mutation
useQuerywill execute on component mount, giving us back the loading, error and data state. Therefore, it is declarativeuseLazyQuerywill 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
useEffectand it would operate similarly touseQuery, sinceuseEffectgets run on component mount
- To be clear, you could put this in
useMutationwill 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