Last active
February 15, 2022 13:11
-
-
Save xtiannyeto/b5b5a298d7316604bf3e327955654641 to your computer and use it in GitHub Desktop.
RTK query starter
This file contains hidden or 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 { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' | |
import { Pokemon } from './types' | |
// Define a service using a base URL and expected endpoints | |
export const pokemonApi = createApi({ | |
reducerPath: 'pokemonApi', | |
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }), | |
endpoints: (builder) => ({ | |
getPokemonByName: builder.query<Pokemon, string>({ | |
query: (name) => `pokemon/${name}`, | |
}), | |
}), | |
}) | |
// Export hooks for usage in functional components, which are | |
// auto-generated based on the defined endpoints | |
export const { useGetPokemonByNameQuery } = pokemonApi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment