一.基础文件结构
二.文件详情
1.store/index.ts
import { applyMiddleware, createStore } from 'redux'
import rootRouter from './reducers'
import { composeWithDevTools } from 'redux-devtools-extension'
import thunk, { ThunkAction } from 'redux-thunk'
import { ChannelAction } from './action/channel'
import { ArtilceAction } from './action/article'
const store = createStore(
rootRouter,
composeWithDevTools(applyMiddleware(thunk))
)
// 一劳永逸解决 useSelector 类型问题
console.log(11111, store.getState())
type Fn = typeof store.getState
export type RootState = ReturnType<Fn>
// 解决thunk调用函数时类型问题
export type RootAction = ThunkAction<
void,
RootState,
unknown,
ChannelAction | ArtilceAction
>
export default store