Skip to content

Disable fetch on mount but fetch on variable change without using refetch #805

Discussion options

You must be logged in to vote

Hi @eoghanmccarthy
Did you try something like this?

const [imageUrl, setImageUrl] = useState();

const imageQuery = useImage(imageId, {
    onSuccess: res => {
        setImageUrl(res.data.imageUrl);
    }
});

const imageProxyQuery = useImageProxy(imageUrl, {
-    enabled: false,
+    enabled: imageUrl,
});

See https://react-query.tanstack.com/docs/guides/queries#dependent-queries

Also, you might not need that imageUrl state - it can be derived from imageQuery:

const imageQuery = useImage(imageId);

const imageUrl = imageQuery.data ? imageQuery.data.imageUrl : null;

const imageProxyQuery = useImageProxy(imageUrl, {
    enabled: imageUrl,
});

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@eoghanmccarthy
Comment options

Answer selected by eoghanmccarthy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants