@raydeck/useimperativequery
v1.0.2
Published
Imperative query hook for apollo-hooks
Downloads
3
Maintainers
Readme
useimperativequery
Hook for triggering a query imperatively (like we do with useMutation) in apollo with hooks
Usage: useImperativeQuery(query: DocumentNode): Tuple
Use just like you do useMutation. ANd it will run the query every time, unlike useLazyQuery
.
Example
import useImperativeQuery from "@raydeck/useimperativequery";
//...
const ComponentOfMine = (props) => {
const [queryRunner] = useImperativeQuery(query);
const onPress = useCallback(
async (thing) => {
const results = await queryRunner({ variables: { argument: thing } });
console.log(results); //Now do something with the newly-fetched relevant data!
},
[queryRunner]
);
};