2017-07-25 7 views
0

私は上記の問題を抱えています、私はthisを試しましたが、運はありません。ここストアには有効なレデューサーがありません。反応する還元

は私の店です:

import { compose, combineReducers, applyMiddleware, createStore } from "redux"; 
import thunkMiddleware from "redux-thunk"; 
import * as activities from "../reducers/activities"; 
import * as location from "../reducers/location"; 

const configureStore = railsProps => { 
    const composedStore = compose(
    applyMiddleware(thunkMiddleware), 
    window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() 
); 

    const combinedReducers = combineReducers({ 
    location, 
    activities 
    }); 
    return composedStore(createStore)(combinedReducers, railsProps); 
}; 

export default configureStore; 

ここに私の場所の減速です:

import { combineReducers } from "redux"; 
import * as actions from "../constants/constants"; 

const coordinates = (state = {}, action) => { 
    switch (action.type) { 
    case actions.GET_LOCATION_SUCCESS: 
    case actions.GET_LOCATION_REQUEST: 
    case actions.GET_LOCATION_FAILURE: 
    default: 
     return state; 
    } 
}; 

const reducer = coordinates; 

export default reducer; 

は、ここに私の活動の減速です:

import { combineReducers } from "redux"; 
import * as actions from "../constants/constants"; 

const page = (state = 0, action) => { 
    switch (action.type) { 
    case actions.NEXT_ACTIVITY_PAGE: 
     return action.page < action.totalPages - 1 
     ? action.page + 1 
     : action.page; 
    case actions.PREV_ACTIVITY_PAGE: 
     return action.page > 0 ? action.page - 1 : 0; 
    default: 
     return state; 
    } 
}; 

const activities = (state = {}, action) => { 
    switch (action.type) { 
    case actions.FETCH_ACTIVITIES_SUCCESS: { 
     return state.concat(action.activities); 
    } 
    case actions.FETCH_ACTIVITIES_REQUEST: 

    case actions.FETCH_ACTIVITIES_FAILURE: 

    default: 
     return state; 
    } 
}; 

const reducer = combineReducers({ page, activities }); 

export default reducer; 

私はそれがcombineReducers方法とは何かを持っていると思いますどのように私はものをインポートするが、私はそこに何が間違っているのか分からない。これは間違っている

+1

http://redux.js.org/docs/api/combineReducers.htmlおそらく、あなたは '.. * from location from" ../ reducers/location ";'を 'import location from"から置き換えるべきです.. ../reducers/ location ";'( 'arguments'セクションの下にあるそのインポートステートメントに関してリンクされたページにメモがあります)。私の活動ファイルには –

答えて

1

ありがとう:あなたの減速がデフォルト輸出している間、上記

import * as activities from "../reducers/activities"; 
import * as location from "../reducers/location"; 

は、ファイルからのすべての名前付き輸出をエクスポートします。

は訂正:

import activities from "../reducers/activities"; 
import location from "../reducers/location"; 

をEDIT:

ファイルからレデューサーをエクスポートする場合は、それらが命名します:

export const page = (state = 0, action) => { 
    switch (action.type) { 
    ... 
    } 
}; 

export const activities = (state = {}, action) => { 
    switch (action.type) { 
    ... 
    } 
}; 

以降:

import { page, activities } from 'path/to/file.js'; 
+0

があります。私は 'ページ'を持っていて、 'アクティビティ'還元人はこれを別ファイルにするべきですか? –

+0

別々のファイルで管理したいと思ったら、それを行うのが良いでしょう。 – Tomasz

+0

しかし、ファイルごとに 'export default'を1つだけ持つことができ、' page'と 'activities'をエクスポートする必要がある場合はどうしたらいいですか? –

関連する問題