Skip to content

Instantly share code, notes, and snippets.

@danielkcz
Last active February 19, 2019 18:42
Embed
What would you like to do?
useQuery reusable
import { observer } from 'mobx-react-lite'
const RandomGiphy = observer(() => {
const settings = useSettings()
const giphy = useRandomGiphy(settings.tag)
return giphy ? <img src={giphy.url} /> : null
})
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