Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@danielkcz
Last active February 19, 2019 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielkcz/7bb72cb9ce37ce8f2c4768ed46013428 to your computer and use it in GitHub Desktop.
Save danielkcz/7bb72cb9ce37ce8f2c4768ed46013428 to your computer and use it in GitHub Desktop.
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