I have a custom debounce hook for apollo lazy queries:
import {useLazyQuery} from '@apollo/react-hooks';
import debounce from "lodash/debounce";
export function useDebouncedQuery(schema) {
const [doQuery, {...rest}] = useLazyQuery(schema);
const query = React.useCallback(debounce(doQuery, 1000), []);
return [query, {
...rest
}]
}
This works, other than the onCompleted
option. When implementing the hook like this:
const [doQuery] = useDebouncedQuery(query);
doQuery({
onCompleted: data => {
console.log(data);
}
})
...the onCompleted
option doesn't fire. But, if I change the hook to be:
export function useAsyncSelectQuery(schema, options) {
const [doQuery, {...rest}] = _useLazyQuery(schema, options);
...
.. and implement it like this, it works:
const [doQuery] = useDebouncedQuery(query, {
onCompleted: data => {
console.log(data);
}
});
Why is this? Am I doing something wrong? I have separate logic that needs to handle the data passed to onCompleted
in different places so I can't pass that option when the query gets initialized. Any help is greatly appreciated.
onCompleted
doesn't exist onuseLazyQuery
– Fitzhugh