@@ -448,7 +448,6 @@ React Redux supports creating `hooks` (and `connect`) with a [custom context](ht
448448import { createContext } from ' react'
449449import {
450450 ReactReduxContextValue ,
451- TypedUseSelectorHook ,
452451 createDispatchHook ,
453452 createSelectorHook ,
454453 createStoreHook ,
@@ -458,10 +457,9 @@ import { AppStore, RootState, AppDispatch } from './store'
458457// highlight-next-line
459458const 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
467465In 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:
472470import { createContext } from ' react'
473471import {
474472 ReactReduxContextValue ,
475- TypedUseSelectorHook ,
476473 createDispatchHook ,
477474 createSelectorHook ,
478475 createStoreHook ,
@@ -482,10 +479,9 @@ import { AppStore, RootState, AppDispatch } from './store'
482479// highlight-next-line
483480const 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 >
0 commit comments