2017-12-23 25 views
0

を返します。私はインポートをコメントアウトするとすぐに私は私のコンポーネント/コンテナの1からimport { getUser } from '../../modules/user'がそうであるように、私はできるだけ早くReduxのインポート副作用は、私は、次のReduxのモジュールをしているリデューサー返さ未定義

Error: Reducer "user" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined.

で打撃を受ける、モジュールを使用する他のすべてが正常に動作し続けます。その新しい副作用について、それは何ですか?これは、これを引き起こしている他のものと同じように見えますか?

は、店舗コードを作成するマイ:

import { createStore, applyMiddleware, compose } from 'redux' 
import { ConnectedRouter, routerReducer, routerMiddleware, push } from 'react-router-redux' 
import createHistory from 'history/createBrowserHistory' 
import { combineReducers } from 'redux-immutablejs' 
import { fromJS, Map } from 'immutable' 
import thunk from 'redux-thunk' 
import user from '../modules/user' 

const initialState = fromJS({}) 
const enhancers = [] 

const middleware = [ 
    thunk, 
    routerMiddleware(history) 
] 

export const history = createHistory() 

const reducer = combineReducers({ 
    user, 
    router: routerReducer, 
}) 

if (process.env.NODE_ENV === 'development') { 
    const devToolsExtension = window.devToolsExtension 

    if (typeof devToolsExtension === 'function') { 
    enhancers.push(devToolsExtension()) 
    } 
} 

const composedEnhancers = compose(
    applyMiddleware(...middleware), 
    ...enhancers 
) 

const store = createStore(
    reducer, 
    initialState, 
    composedEnhancers 
) 

export default store 

を私は減速のデフォルトのparam部分に直接初期状態地図を移動することで、エラーを修正することができます...別のconstでそれを持ったときにエラーが生成されるようです。しかしそれは、この機能の導入前に数週間のためにそのように働いています...あなたが使用している

例えば

// Reducer 
export default function user (state = Map({ 
    accessToken: null, 
    loginPending: false, 
    loginError: false, 
    creatingAccountTeam: false, 
    creatingAccountTeamSuccess: false, 
    creatingAccountTeamError: Map({}), 
    profile: Map({ 
    id: null, 
    email: null, 
    firstName: null, 
    lastName: null, 
    company: null, 
    mobile: null, 
    mobileShare: true, 
    dob: null 
    }) 
}), action = {}) { 

答えて

1

SETINの構文が間違っている、ネストされたパスが[]内である必要があります。

.setIn(['profile', 'id'], action.payload.id) 
    .setIn(['profile', 'email'], action.payload.email) 
    .setIn(['profile', 'firstName'], action.payload.first_name) 
    .setIn(['profile', 'lastName'], action.payload.last_name) 
    .setIn(['profile', 'company'], action.payload.company) 
    .setIn(['profile', 'mobile'], action.payload.mobile) 
    .setIn(['profile', 'mobileShare'], action.payload.mobile_share) 
    .setIn(['profile', 'dob'], action.payload.dob) 

チェックあなたは

+0

良いスポットがあなたに感謝し、それが解決しなかった矛盾につながる可能性がありnextStateにこれを割り当てるために逃した

if (action.status === 'success') state.set('creatingAccountTeamSuccess', true) . // <-- 

でもこのdocumentation

「リデューサー」ユーザーは「初期化中に未定義に戻った」残念ながら – Titan

+0

'RECEIVE_USER'のcaseステートメントでconsole.log()の状態を変更した結果、 'export const getUser =()=> async dispatch => {'で非同期を削除しても問題ありません。 –

+0

また、ディスパッチする前にgetUser関数呼び出しでユーザーデータを取得したかどうか確認してください –

関連する問題