簡體   English   中英

無法在 redux 中使用 rootReducer,react/typescript

[英]Cannot use rootReducer in redux , react/typescript

我正在使用 react/typescript 學習 redux。 一切都很好,直到我使用了 1 個以上的減速器。 起初,我是這樣創建商店的:

import { AuthReducer } from './reducers/AuthReducer' 
const middleware = [thunk];
const store = createStore (AuthReducer, applyMiddleware(thunk))
export default store

但是當我嘗試使用rootReducer時,我從商店記錄的數據是未定義的。

import { AuthReducer } from './reducers/AuthReducer' 

const middleware = [thunk]; 
const rootReducer=combineReducers({
  AuthReducer, 
  CartReducer 
})

const store = createStore (rootReducer, applyMiddleware(thunk))
export default store
import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk'

import reducers from '../Reducers'
//this is all your reducers that  are combined

const middleWare = [ thunk ]

const store = createStore (
    reducers,
    undefined,
    compose(
        applyMiddleware(...middleWare)
    )
)
export default store;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM