forked from reduxjs/redux-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
38 lines (34 loc) · 770 Bytes
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {
createApi,
fetchBaseQuery,
ApiProvider,
} from '@reduxjs/toolkit/query/react'
const api = createApi({
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2' }),
endpoints: (builder) => ({
getPokemonByName: builder.query({
query: (name: string) => `pokemon/${name}`,
}),
}),
})
function Pokemon() {
const { data, refetch, isFetching } =
api.useGetPokemonByNameQuery('bulbasaur')
return (
<div>
<button onClick={refetch}>Refetch</button>
<div>
<b>isFetching?</b>: {String(isFetching)}
</div>
<hr />
<pre>{JSON.stringify(data, null, 2)}</pre>
</div>
)
}
export default function App() {
return (
<ApiProvider api={api}>
<Pokemon />
</ApiProvider>
)
}