2017-11-08 8 views
0

jsがこのNextjsが

import {createStore, applyMiddleware, combineReducers} from 'redux' 
import {composeWithDevTools} from 'redux-devtools-extension' 
import withRedux from 'next-redux-wrapper' 
import nextReduxSaga from 'next-redux-saga' 
import createSagaMiddleware from 'redux-saga' 

import {initialState} from './initialState' 
import globalSaga from '../sagas/global' 

const sagaMiddleware = createSagaMiddleware() 

export function configureStore (reducers,initialState) { 
    console.log(initialState) 

    let states = {} 
    Object.keys(reducers).map((key) => { 
    states[key] = initialState[key] 
    }) 

    console.log(reducers) 
    console.log(states) 
    const store = createStore(
    combineReducers({reducers}), 
    states, 
    composeWithDevTools(applyMiddleware(sagaMiddleware)) 
) 
    store.sagaTask = sagaMiddleware.run(globalSaga) 
    return store 
} 

export function withReduxSaga (BaseComponent, reducers) { 
    return withRedux(configureStore(reducers,initialState))(nextReduxSaga(BaseComponent)) 
} 

export default function configureWithReduxSaga(component,reducers){ 
    return withReduxSaga(component,reducers) 
} 

のような店を初期化し、誤りがある

Store does not have a valid reducer. Make sure the argument passed to 

makeStore is not a function 

間違っているかもしれない何を、基本的に私は追加機能を書きたい減速store.global多くのコードなしでnextjsコンポーネントに特定のサガを使用すると、次のようなものが最適です。

configureWithReduxSaga(
{reducer1, reducer2}, 
{saga1, saga2} 
) 

は可能ですか?ルートレデューサーとルートサーガを作成して、すべてのコンポーネントに渡すことができます。これはコード化するのが難しくありませんが、それは実行可能ですか?

答えて

0
combineReducers({reducers}), 

ほとんどの場合、減速材の辞書がありますが、冗長なオブジェクトに包まれている可能性があります。その場合は、残りのスプレッド演算子combineReducers({...reducers})または単純オブジェクト渡しcombineReducers(reducers)を使用してください。それについてのオリジナルのドキュメントを参照してください:https://redux.js.org/docs/api/combineReducers.html#arguments

reducersが配列の場合は、それを反復処理し、各レデューサーに自分の名前を付けます。