2016-10-14 12 views
0

私のコードが私のレデューサー(現在は私はフォルダー内に1つのレデューサーしかありません)を呼んでいないと私は説明することができますreduxロガーを活性化しません。私のコンソールは、任意の情報やエラーReduxレデューサーは発送後に呼び出されません

メインindex.jsx

import React from "react"; 
import ReactDOM from "react-dom"; 
import { Provider } from 'react-redux'; 
import { createStore, combineReducers, applyMiddleware } from 'redux'; 
import logger from 'redux-logger'; 
import App from './containers/App.jsx'; 
import * as reducers from './reducers' 
import types from './constants/actions'; 

const reducer = combineReducers(reducers); 

const destination = document.querySelector("#container"); 
const createStoreWithMiddleware = applyMiddleware(logger)(createStore); 

let store = createStoreWithMiddleware(reducer, { 
userName: 'N/A' 
}); 


ReactDOM.render(
<Provider store={store}> 
    <App/> 
</Provider>, 
destination 
); 

console.log(1) //<----- CONSOLE.LOG 
store.dispatch({ 
      type: types.LOAD_USER_NAME, 
      name : '' 
}) 

マイ減速

import types from './../constants/actions' 

const userName = (state = {userName : "N/A"}, action) => { 
console.log('inside reducer'); //<----- CONSOLE.LOG 
switch (action.type) { 
    case types.LOAD_USER_NAME: 
     console.log('before change state') 
     return action.data; 
    default: 
     return '_N/A' 
} 
} 

export {userName} 

./constants/actions何が存在しない、空で

module.exports = Object.freeze({ 
LOAD_USER_NAME : 'LOAD_USER_NAME' 

}) 
私は、以下の情報をコンソールに表示

AFTE実行:私はコンソール少なくとも一つの私の減速は、呼び出しがあったことを意味し、より多くの時間inside reducerに表示することを望んだ

enter image description here

+0

'聞かせて店= createStoreWithMiddleware(減速、{' VAR 'へを変更してみてください作業を開始store = createStoreWithMiddleware(reducer、{' – Panther

+1

store.dispatchを呼び出す前にresponse.json()を解決しようとしましたか? – StackOverMySoul

+0

@Davidlrntはい、読めます'response.json() 'のデータ –

答えて

0

私のコードの主な問題は、適用ミドルウェアです。

私は、このコードsubstited:以下の1オン

const createStoreWithMiddleware = applyMiddleware(logger)(createStore); 

let store = createStoreWithMiddleware(reducer, { 
    userName: 'N/A' 
}); 

const log = logger(); 

const store = createStore(
    reducer, 
    { 
     userName : 'N/A' 
    }, 
    applyMiddleware(log) 
); 

を、すべてが

関連する問題