Created
January 8, 2023 21:10
-
-
Save kivircik-parantez/1d0e1878c54641dc40fa69f81ca68dfa to your computer and use it in GitHub Desktop.
Using RTK Query Hooks in Components
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 * 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