2016-12-21 14 views
1

ページを入力するときにアクションをディスパッチしようとしていますが、何らかの理由によりディスパッチされたアクションの無限ループが発生します。私はシンプルにconsole.logでの発送を交換しようとしました、これは発生しませんonEnterからアクションをディスパッチするときの最大コールスタックサイズを超えました

const routes = (store) => { 
    const test = (nextState, replace, callback) => { 
    Promise.resolve(store.dispatch({type: 'test'})).then(callback()); 
    }; 

    return (
    <Route path="/" component={App}> 
     <IndexRoute component={LoginPage}/> 
     <Route path="/home" component={HomePage} onEnter={test}/> 
    </Route> 
    ); 
}; 

は、ここに私のコードです。 これは、onEnterからディスパッチしようとするときだけです

答えて

0

私はimmutablejsを使用しており、react-router-reduxを適切に設定していなかったためでした。

私が持っていた:

const history = syncHistoryWithStore(browserHistory, store, { selectLocationState(state) { 
    return state 
     .get('routing') 
     .toJS(); 
    }}); 

私は今の代わりに使用しています:

const createSelectLocationState =() => { 
    let prevRoutingState, 
    prevRoutingStateJS; 
    return (state) => { 
    const routingState = state.get('routing'); // or state.routing 
    if (typeof prevRoutingState === 'undefined' || prevRoutingState !== routingState) { 
     prevRoutingState = routingState; 
     prevRoutingStateJS = routingState.toJS(); 
    } 
    return prevRoutingStateJS; 
    }; 
}; 

const history = syncHistoryWithStore(browserHistory, store, {selectLocationState: createSelectLocationState()}); 
をし、それが正しく機能しています。

出典:https://github.com/sjparsons/react-router-redux-immutable

関連する問題