Created
October 2, 2022 14:10
-
-
Save AlaBenAicha/22703f4292ead5ccfe86d7b0ec4754f5 to your computer and use it in GitHub Desktop.
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 '@rtk-incubator/rtk-query'; | |
// Define a service using a base URL and expected endpoints | |
export const pokemonApi = createApi({ | |
reducerPath: 'pokemonApi', | |
// baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }), // uncomment for brokenness repro ur welcome :) | |
baseQuery: async (baseUrl, prepareHeaders, ...rest) => { | |
const response = await fetch(`https://pokeapi.co/api/v2/${baseUrl}`, rest) | |
return {data: await response.json()} | |
}, | |
endpoints: (builder) => ({ | |
getPokemonByName: builder.query({ | |
query: (name) => `pokemon/${name}`, | |
}), | |
getPokemonList: builder.query({ | |
query: () => `pokemon` | |
}) | |
}), | |
}); | |
// 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