diff --git a/superset-frontend/src/hooks/apiResources/tables.test.ts b/superset-frontend/src/hooks/apiResources/tables.test.ts index d2f80fe0a26..4e7abc4fd79 100644 --- a/superset-frontend/src/hooks/apiResources/tables.test.ts +++ b/superset-frontend/src/hooks/apiResources/tables.test.ts @@ -251,7 +251,7 @@ describe('useTables hook', () => { fetchMock.get(`glob:*/api/v1/database/${expectDbId}/schemas/*`, { result: fakeSchemaApiResult, }); - const { result, waitFor } = renderHook( + const { result } = renderHook( () => useTables({ dbId: expectDbId, diff --git a/superset-frontend/src/views/store.ts b/superset-frontend/src/views/store.ts index c200fdc9969..e6e996f6aba 100644 --- a/superset-frontend/src/views/store.ts +++ b/superset-frontend/src/views/store.ts @@ -22,6 +22,11 @@ import { createListenerMiddleware, StoreEnhancer, } from '@reduxjs/toolkit'; +import { + useDispatch, + useSelector, + type TypedUseSelectorHook, +} from 'react-redux'; import thunk from 'redux-thunk'; import { api } from 'src/hooks/apiResources/queryApi'; import messageToastReducer from 'src/components/MessageToasts/reducers'; @@ -177,3 +182,12 @@ export function setupStore({ export const store = setupStore(); export type RootState = ReturnType; + +// Typed Redux hooks. Prefer these over the raw `useDispatch` / `useSelector` +// from react-redux: `useAppDispatch` understands the store's middleware (so +// thunks resolve correctly), and `useAppSelector` infers `RootState` without +// callers having to annotate every selector. Required ahead of the +// react-redux v8+ bump, which tightens dispatch typing — see #39927. +export type AppDispatch = typeof store.dispatch; +export const useAppDispatch: () => AppDispatch = useDispatch; +export const useAppSelector: TypedUseSelectorHook = useSelector;