Last active
February 19, 2019 18:42
-
-
Save danielkcz/7bb72cb9ce37ce8f2c4768ed46013428 to your computer and use it in GitHub Desktop.
useQuery reusable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { observer } from 'mobx-react-lite' | |
const RandomGiphy = observer(() => { | |
const settings = useSettings() | |
const giphy = useRandomGiphy(settings.tag) | |
return giphy ? <img src={giphy.url} /> : null | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useDisposable } from 'mobx-react-lite' | |
export function useRandomGiphy(tag) { | |
const { data, refetch } = useQuery( | |
RandomGiphyQuery, { | |
variables: { tag } | |
} | |
) | |
return data ? data.giphy.random : null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment