Skip to content

Commit 0d55413

Browse files
committed
Merge branch 'master' into create-slice-creators
2 parents bde0288 + fd52689 commit 0d55413

22 files changed

+217
-78
lines changed

.github/workflows/test-codegen.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
filters: |
2323
codegen:
2424
- 'packages/rtk-query-codegen-openapi/**'
25+
- 'yarn.lock'
2526
2627
build:
2728
needs: changes

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
- 'packages/toolkit/**'
2121
- 'examples/publish-ci/**'
2222
- '.github/workflows/tests.yml'
23+
- 'yarn.lock'
2324
2425
build:
2526
needs: changes

docs/api/autoBatchEnhancer.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Any action that is tagged with `action.meta[SHOULD_AUTOBATCH] = true` will be tr
9999

100100
- `{type: 'raf'}`: queues using `requestAnimationFrame` (default)
101101
- `{type: 'tick'}`: queues using `queueMicrotask`
102-
- `{type: 'timer, timeout: number}`: queues using `setTimeout`
102+
- `{type: 'timer', timeout: number}`: queues using `setTimeout`
103103
- `{type: 'callback', queueNotification: (notify: () => void) => void}`: lets you provide your own callback, such as a debounced or throttled function
104104

105105
The default behavior is to queue the notifications using `requestAnimationFrame`.

docs/tutorials/typescript.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,12 @@ Since these are actual variables, not types, it's important to define them in a
7676
7777
```ts title="app/hooks.ts"
7878
import { useDispatch, useSelector } from 'react-redux'
79-
import type { TypedUseSelectorHook } from 'react-redux'
8079
import type { RootState, AppDispatch } from './store'
8180

8281
// highlight-start
8382
// Use throughout your app instead of plain `useDispatch` and `useSelector`
84-
export const useAppDispatch: () => AppDispatch = useDispatch
85-
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
83+
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
84+
export const useAppSelector = useSelector.withTypes<RootState>()
8685
// highlight-end
8786
```
8887

docs/usage/migrating-rtk-2.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ React Redux supports creating `hooks` (and `connect`) with a [custom context](ht
448448
import { createContext } from 'react'
449449
import {
450450
ReactReduxContextValue,
451-
TypedUseSelectorHook,
452451
createDispatchHook,
453452
createSelectorHook,
454453
createStoreHook,
@@ -458,10 +457,9 @@ import { AppStore, RootState, AppDispatch } from './store'
458457
// highlight-next-line
459458
const context = createContext<ReactReduxContextValue>(null as any)
460459

461-
export const useStore: () => AppStore = createStoreHook(context)
462-
export const useDispatch: () => AppDispatch = createDispatchHook(context)
463-
export const useSelector: TypedUseSelectorHook<RootState> =
464-
createSelectorHook(context)
460+
export const useStore = createStoreHook(context).withTypes<AppStore>()
461+
export const useDispatch = createDispatchHook(context).withTypes<AppDispatch>()
462+
export const useSelector = createSelectorHook(context).withTypes<RootState>()
465463
```
466464

467465
In v9, the types now match the runtime behaviour. The context is typed to hold `ReactReduxContextValue | null`, and the hooks know that if they receive `null` they'll throw an error so it doesn't affect the return type.
@@ -472,7 +470,6 @@ The above example now becomes:
472470
import { createContext } from 'react'
473471
import {
474472
ReactReduxContextValue,
475-
TypedUseSelectorHook,
476473
createDispatchHook,
477474
createSelectorHook,
478475
createStoreHook,
@@ -482,10 +479,9 @@ import { AppStore, RootState, AppDispatch } from './store'
482479
// highlight-next-line
483480
const context = createContext<ReactReduxContextValue | null>(null)
484481

485-
export const useStore: () => AppStore = createStoreHook(context)
486-
export const useDispatch: () => AppDispatch = createDispatchHook(context)
487-
export const useSelector: TypedUseSelectorHook<RootState> =
488-
createSelectorHook(context)
482+
export const useStore = createStoreHook(context).withTypes<AppStore>()
483+
export const useDispatch = createDispatchHook(context).withTypes<AppDispatch>()
484+
export const useSelector = createSelectorHook(context).withTypes<RootState>()
489485
```
490486

491487
</div>

docs/usage/migrating-to-modern-redux.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,13 +1110,13 @@ Per [our standard TypeScript setup and usage guidelines](../tutorials/typescript
11101110
First, set up the hooks:
11111111

11121112
```ts no-transpile title="src/app/hooks.ts"
1113-
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'
1113+
import { useDispatch, useSelector } from 'react-redux'
11141114
import type { RootState, AppDispatch } from './store'
11151115

11161116
// highlight-start
11171117
// Use throughout your app instead of plain `useDispatch` and `useSelector`
1118-
export const useAppDispatch: () => AppDispatch = useDispatch
1119-
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
1118+
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
1119+
export const useAppSelector = useSelector.withTypes<RootState>()
11201120
// highlight-end
11211121
```
11221122

docs/usage/nextjs.mdx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,13 @@ export type AppDispatch = AppStore['dispatch']
135135

136136
// file: lib/hooks.ts
137137
import { useDispatch, useSelector, useStore } from 'react-redux'
138-
import type { TypedUseSelectorHook } from 'react-redux'
139138
import type { RootState, AppDispatch, AppStore } from './store'
140139

141140
// highlight-start
142141
// Use throughout your app instead of plain `useDispatch` and `useSelector`
143-
export const useAppDispatch: () => AppDispatch = useDispatch
144-
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
145-
export const useAppStore: () => AppStore = useStore
142+
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
143+
export const useAppSelector = useSelector.withTypes<RootState>()
144+
export const useAppStore = useStore.withTypes<AppStore>()
146145
// highlight-end
147146
```
148147

@@ -330,14 +329,13 @@ export type AppDispatch = AppStore['dispatch']
330329

331330
// file: lib/hooks.ts noEmit
332331
import { useDispatch, useSelector, useStore } from 'react-redux'
333-
import type { TypedUseSelectorHook } from 'react-redux'
334332
import type { RootState, AppDispatch, AppStore } from './store'
335333

336334
// highlight-start
337335
// Use throughout your app instead of plain `useDispatch` and `useSelector`
338-
export const useAppDispatch: () => AppDispatch = useDispatch
339-
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
340-
export const useAppStore: () => AppStore = useStore
336+
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
337+
export const useAppSelector = useSelector.withTypes<RootState>()
338+
export const useAppStore = useStore.withTypes<AppStore>()
341339
// highlight-end
342340

343341
/* prettier-ignore */

docs/usage/usage-with-typescript.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The basics of using `configureStore` are shown in [TypeScript Quick Start tutori
3535

3636
### Getting the `State` type
3737

38-
The easiest way of getting the `State` type is to define the root reducer in advance and extract its `ReturnType`.
38+
The easiest way of getting the `State` type is to define the root reducer in advance and extract its `ReturnType`.
3939
It is recommended to give the type a different name like `RootState` to prevent confusion, as the type name `State` is usually overused.
4040

4141
```typescript
@@ -89,7 +89,7 @@ const store = configureStore({
8989

9090
// highlight-start
9191
export type AppDispatch = typeof store.dispatch
92-
export const useAppDispatch: () => AppDispatch = useDispatch // Export a hook that can be reused to resolve types
92+
export const useAppDispatch = useDispatch.withTypes<AppDispatch>() // Export a hook that can be reused to resolve types
9393
// highlight-end
9494

9595
export default store

errors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@
4747
"45": "context.exposeAction cannot be called twice for the same reducer definition: reducerName",
4848
"46": "context.exposeCaseReducer cannot be called twice for the same reducer definition: reducerName",
4949
"47": "Could not find \"\" slice in state. In order for slice creators to use \\`context.selectSlice\\`, the slice must be nested in the state under its reducerPath: \"\""
50-
}
50+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@babel/types": "7.19.3",
5151
"esbuild": "0.19.7",
5252
"jest-snapshot": "29.3.1",
53-
"react-redux": "npm:8.0.2",
53+
"react-redux": "npm:9.1.0",
5454
"react": "npm:18.2.0",
5555
"react-dom": "npm:18.2.0",
5656
"resolve": "1.22.1",

0 commit comments

Comments
 (0)