Skip to content

Instantly share code, notes, and snippets.

@kivircik-parantez
Created January 8, 2023 21:10
Show Gist options
  • Save kivircik-parantez/1d0e1878c54641dc40fa69f81ca68dfa to your computer and use it in GitHub Desktop.
Save kivircik-parantez/1d0e1878c54641dc40fa69f81ca68dfa to your computer and use it in GitHub Desktop.
Using RTK Query Hooks in Components
import * as React from 'react'
import { useGetPokemonByNameQuery } from './services/pokemon'
export default function App() {
// Using a query hook automatically fetches data and returns query values
const { data, error, isLoading } = useGetPokemonByNameQuery('bulbasaur')
// Individual hooks are also accessible under the generated endpoints:
// const { data, error, isLoading } = pokemonApi.endpoints.getPokemonByName.useQuery('bulbasaur')
// render UI based on data and loading state
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment