Skip to content

Commit 6f72cfd

Browse files
committed
Merge branch 'master' of https://github.com/reduxjs/redux-toolkit into configs
2 parents d001ac3 + ed9fc19 commit 6f72cfd

File tree

53 files changed

+2968
-2967
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2968
-2967
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf
+33-33
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
import { useGetPokemonByNameQuery } from './services/pokemon'
2-
3-
export const Pokemon = ({
4-
name,
5-
pollingInterval,
6-
}: {
7-
name: string
8-
pollingInterval: number
9-
}) => {
10-
const { data, error, isLoading, isFetching } = useGetPokemonByNameQuery(
11-
name,
12-
{
13-
pollingInterval,
14-
},
15-
)
16-
17-
return (
18-
<>
19-
{error ? (
20-
<>Oh no, there was an error</>
21-
) : isLoading ? (
22-
<>Loading...</>
23-
) : data ? (
24-
<>
25-
<h3>
26-
{data.species.name} {isFetching ? '...' : ''}
27-
</h3>
28-
<img src={data.sprites.front_shiny} alt={data.species.name} />
29-
</>
30-
) : null}
31-
</>
32-
)
33-
}
1+
import { useGetPokemonByNameQuery } from './services/pokemon'
2+
3+
export const Pokemon = ({
4+
name,
5+
pollingInterval,
6+
}: {
7+
name: string
8+
pollingInterval: number
9+
}) => {
10+
const { data, error, isLoading, isFetching } = useGetPokemonByNameQuery(
11+
name,
12+
{
13+
pollingInterval,
14+
},
15+
)
16+
17+
return (
18+
<>
19+
{error ? (
20+
<>Oh no, there was an error</>
21+
) : isLoading ? (
22+
<>Loading...</>
23+
) : data ? (
24+
<>
25+
<h3>
26+
{data.species.name} {isFetching ? '...' : ''}
27+
</h3>
28+
<img src={data.sprites.front_shiny} alt={data.species.name} />
29+
</>
30+
) : null}
31+
</>
32+
)
33+
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
2-
3-
export const pokemonApi = createApi({
4-
reducerPath: 'pokemonApi',
5-
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
6-
tagTypes: [],
7-
endpoints: (builder) => ({
8-
getPokemonByName: builder.query({
9-
query: (name: string) => `pokemon/${name}`,
10-
}),
11-
}),
12-
})
13-
14-
// Export hooks for usage in functional components
15-
export const { useGetPokemonByNameQuery } = pokemonApi
1+
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
2+
3+
export const pokemonApi = createApi({
4+
reducerPath: 'pokemonApi',
5+
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
6+
tagTypes: [],
7+
endpoints: (builder) => ({
8+
getPokemonByName: builder.query({
9+
query: (name: string) => `pokemon/${name}`,
10+
}),
11+
}),
12+
})
13+
14+
// Export hooks for usage in functional components
15+
export const { useGetPokemonByNameQuery } = pokemonApi
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setupWorker } from 'msw'
2-
import { handlers } from './handlers'
3-
4-
export const worker = setupWorker(...handlers)
1+
import { setupWorker } from 'msw'
2+
import { handlers } from './handlers'
3+
4+
export const worker = setupWorker(...handlers)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setupWorker } from 'msw'
2-
import { handlers } from './handlers'
3-
4-
export const worker = setupWorker(...handlers)
1+
import { setupWorker } from 'msw'
2+
import { handlers } from './handlers'
3+
4+
export const worker = setupWorker(...handlers)
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
2-
3-
export const pokemonApi = createApi({
4-
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
5-
tagTypes: [],
6-
endpoints: (builder) => ({
7-
getPokemonByName: builder.query({
8-
query: (name: string) => `pokemon/${name}`,
9-
}),
10-
}),
11-
})
12-
13-
// Export hooks for usage in functional components
14-
export const { useGetPokemonByNameQuery } = pokemonApi
1+
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
2+
3+
export const pokemonApi = createApi({
4+
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
5+
tagTypes: [],
6+
endpoints: (builder) => ({
7+
getPokemonByName: builder.query({
8+
query: (name: string) => `pokemon/${name}`,
9+
}),
10+
}),
11+
})
12+
13+
// Export hooks for usage in functional components
14+
export const { useGetPokemonByNameQuery } = pokemonApi
+21-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { combineReducers, configureStore } from '@reduxjs/toolkit'
2-
import type { PreloadedState } from '@reduxjs/toolkit'
3-
import { pokemonApi } from './services/pokemon'
4-
5-
const rootReducer = combineReducers({
6-
[pokemonApi.reducerPath]: pokemonApi.reducer,
7-
})
8-
9-
export const setupStore = (preloadedState?: PreloadedState<RootState>) => {
10-
return configureStore({
11-
reducer: rootReducer,
12-
middleware: (getDefaultMiddleware) =>
13-
// adding the api middleware enables caching, invalidation, polling and other features of `rtk-query`
14-
getDefaultMiddleware().concat(pokemonApi.middleware),
15-
preloadedState,
16-
})
17-
}
18-
19-
export type RootState = ReturnType<typeof rootReducer>
20-
export type AppStore = ReturnType<typeof setupStore>
21-
export type AppDispatch = AppStore['dispatch']
1+
import { combineReducers, configureStore } from '@reduxjs/toolkit'
2+
import type { PreloadedState } from '@reduxjs/toolkit'
3+
import { pokemonApi } from './services/pokemon'
4+
5+
const rootReducer = combineReducers({
6+
[pokemonApi.reducerPath]: pokemonApi.reducer,
7+
})
8+
9+
export const setupStore = (preloadedState?: PreloadedState<RootState>) => {
10+
return configureStore({
11+
reducer: rootReducer,
12+
middleware: (getDefaultMiddleware) =>
13+
// adding the api middleware enables caching, invalidation, polling and other features of `rtk-query`
14+
getDefaultMiddleware().concat(pokemonApi.middleware),
15+
preloadedState,
16+
})
17+
}
18+
19+
export type RootState = ReturnType<typeof rootReducer>
20+
export type AppStore = ReturnType<typeof setupStore>
21+
export type AppDispatch = AppStore['dispatch']
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
2-
import type { PokemonName } from '../pokemon.data'
3-
4-
export const pokemonApi = createApi({
5-
reducerPath: 'pokemonApi',
6-
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
7-
endpoints: (builder) => ({
8-
getPokemonByName: builder.query({
9-
query: (name: PokemonName) => `pokemon/${name}`,
10-
}),
11-
}),
12-
})
13-
14-
// Export hooks for usage in functional components
15-
export const { useGetPokemonByNameQuery } = pokemonApi
1+
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
2+
import type { PokemonName } from '../pokemon.data'
3+
4+
export const pokemonApi = createApi({
5+
reducerPath: 'pokemonApi',
6+
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
7+
endpoints: (builder) => ({
8+
getPokemonByName: builder.query({
9+
query: (name: PokemonName) => `pokemon/${name}`,
10+
}),
11+
}),
12+
})
13+
14+
// Export hooks for usage in functional components
15+
export const { useGetPokemonByNameQuery } = pokemonApi
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { configureStore } from '@reduxjs/toolkit'
2-
import { pokemonApi } from './services/pokemon'
3-
4-
export const store = configureStore({
5-
reducer: {
6-
[pokemonApi.reducerPath]: pokemonApi.reducer,
7-
},
8-
// adding the api middleware enables caching, invalidation, polling and other features of `rtk-query`
9-
middleware: (getDefaultMiddleware) =>
10-
getDefaultMiddleware().concat(pokemonApi.middleware),
11-
})
1+
import { configureStore } from '@reduxjs/toolkit'
2+
import { pokemonApi } from './services/pokemon'
3+
4+
export const store = configureStore({
5+
reducer: {
6+
[pokemonApi.reducerPath]: pokemonApi.reducer,
7+
},
8+
// adding the api middleware enables caching, invalidation, polling and other features of `rtk-query`
9+
middleware: (getDefaultMiddleware) =>
10+
getDefaultMiddleware().concat(pokemonApi.middleware),
11+
})
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
2-
3-
export const pokemonApi = createApi({
4-
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
5-
endpoints: (builder) => ({
6-
getPokemonByName: builder.query({
7-
query: (name: string) => `pokemon/${name}`,
8-
}),
9-
}),
10-
})
11-
12-
// Export hooks for usage in functional components
13-
export const { useGetPokemonByNameQuery } = pokemonApi
1+
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
2+
3+
export const pokemonApi = createApi({
4+
baseQuery: fetchBaseQuery({ baseUrl: 'https://pokeapi.co/api/v2/' }),
5+
endpoints: (builder) => ({
6+
getPokemonByName: builder.query({
7+
query: (name: string) => `pokemon/${name}`,
8+
}),
9+
}),
10+
})
11+
12+
// Export hooks for usage in functional components
13+
export const { useGetPokemonByNameQuery } = pokemonApi
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { configureStore } from '@reduxjs/toolkit'
2-
import { pokemonApi } from './services/pokemon'
3-
4-
export const store = configureStore({
5-
reducer: {
6-
[pokemonApi.reducerPath]: pokemonApi.reducer,
7-
},
8-
// adding the api middleware enables caching, invalidation, polling and other features of `rtk-query`
9-
middleware: (getDefaultMiddleware) =>
10-
getDefaultMiddleware().concat(pokemonApi.middleware),
11-
})
1+
import { configureStore } from '@reduxjs/toolkit'
2+
import { pokemonApi } from './services/pokemon'
3+
4+
export const store = configureStore({
5+
reducer: {
6+
[pokemonApi.reducerPath]: pokemonApi.reducer,
7+
},
8+
// adding the api middleware enables caching, invalidation, polling and other features of `rtk-query`
9+
middleware: (getDefaultMiddleware) =>
10+
getDefaultMiddleware().concat(pokemonApi.middleware),
11+
})
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { createApi } from '@reduxjs/toolkit/query/react'
2-
import { graphqlRequestBaseQuery } from '@rtk-query/graphql-request-base-query'
3-
4-
export const api = createApi({
5-
baseQuery: graphqlRequestBaseQuery({
6-
url: '/graphql',
7-
}),
8-
endpoints: () => ({}),
9-
})
1+
import { createApi } from '@reduxjs/toolkit/query/react'
2+
import { graphqlRequestBaseQuery } from '@rtk-query/graphql-request-base-query'
3+
4+
export const api = createApi({
5+
baseQuery: graphqlRequestBaseQuery({
6+
url: '/graphql',
7+
}),
8+
endpoints: () => ({}),
9+
})

0 commit comments

Comments
 (0)