组件调用操作仅适用于直接导入

时间:2018-01-06 18:41:38

标签: reactjs react-redux

我有一个Action,它用connect:

映射
export default connect(mapStateToProps, {hideTenantDialog, updateUserInformation })(TenantComponent);

我在一个按钮内调用updateUserInformation。 错误是:

我直接从操作所在的文件中导入它(authentication / authActions.js) 身份验证组件本身有一个index.js,我从操作中导入所有内容并再次导出

这是index.js的代码:

import authReducer from './authReducer';
import { showLogin, fetchProfile, logoutCurrentUser, updateUserInformation } from './authActions';
import { getBearerToken  } from './bearerToken';

export {
    authReducer as AuthReducer,
    showLogin as ShowLoginAction,
    fetchProfile as FetchProfileAction,
    logoutCurrentUser as LogoutAction,
    getBearerToken as GetAuthenticationHeaderToken,
    updateUserInformation
}

所以:当我从(authentication / actions.js)导入updateUserInformation时,一切正常 当我从(authentication / index.js)导入它时,该函数不会映射到props。

任何想法?

更好理解的回购是:GITHUB Ahrimaan

EDIT authActions.js - >

import {
    CURRENT_USER,
    LOGIN_FAILURE,
    LOGIN_SUCCESS,
    LOGIN_WITH_GOOGLE,
    LOGOUT,
    LOGIN_PROCCESING,
    USERINFORMATION_UPDATED,
    USERINFORMATION_UPDATED_FAILED,
    USERINFORMATION_UPDATING
} from './actionTypes';
import { showTenantDialog, hideTenantDialog } from '../tenant';
import { getCurrentProfile, login, logout, updateUser } from './authenticationService';
import { HIDE_TENANT_DIALOG } from '../tenant/actionTypes';

export function showLogin() {
    return (dispatch) => {
        dispatch({ type: LOGIN_PROCCESING });
        login().then(result => {
            if (!result.user.tenant) {
                dispatch(showTenantDialog());
            }
            dispatch({ type: LOGIN_SUCCESS, payload: result.user });
        }).catch(err => {
            dispatch({ type: LOGIN_FAILURE, payload: err });
        })
    }
}

export function updateUserInformation(tenantId) {
    return (dispatch) => {
        dispatch({type:USERINFORMATION_UPDATING})
        let action = updateUser(tenantId).then(result => {
            /* dispatch({
                type:USERINFORMATION_UPDATED,
                payload:result
            }); */
            // Find a better way, the component itself should track if a tenant switch is needed
            dispatch({type:HIDE_TENANT_DIALOG})
        }).catch(err => {
            // globalerror
            dispatch({type:USERINFORMATION_UPDATED_FAILED});
        })
        dispatch(action);
    }
}

export function fetchProfile() {
    return (dispatch) => {
        let profile = getCurrentProfile();
        if (profile) {
            if (!profile.tenant) {
                dispatch(showTenantDialog());
            }
            dispatch({ type: CURRENT_USER, payload: profile });
        }

    }
}

export function logoutCurrentUser() {
    return (dispatch) => {
        logout();
        dispatch({ type: LOGOUT })
    }
}

0 个答案:

没有答案