0
我試圖運行一些使用REDX和REDEX thunk的異步代碼。無論出於何種原因當我嘗試運行代碼操作時顯示爲未定義,並且出現以下錯誤。動作對象顯示爲未定義在REDX
Cannot read property 'type' of undefined
我所有的行動創造者返回一個對象的類型,所以我不知道它是可悲的。
設置我的商店等,其中我收到錯誤此
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View
} from 'react-native';
import App from '~/components/App';
import { createStore, applyMiddleware, combineReducers, compose } from 'redux';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
import * as reducers from './redux';
// import devTools from 'remote-redux-devtools';
const store = createStore(
combineReducers(reducers),
applyMiddleware(thunk)
)
const nimbus =() => {
return (
<Provider store={store}>
<App />
</Provider>
);
}
我authentication.js文件低於
const AUTHENTICATING = 'AUTHENTICATING';
const NOT_AUTHED = 'NOT_AUTHED';
const IS_AUTHED = 'IS_AUTHED';
import { fbAuth, db } from '~/config/firebase';
function authenticating() {
return {
type: AUTHENTICATING
}
}
function notAuthed() {
return {
type: NOT_AUTHED
}
}
function isAuthed() {
return {
type: IS_AUTHED
}
}
export function createUser (userData) {
return function (dispatch, getState) {
dispatch(authenticating());
const email = userData.email;
const password = userData.password;
fbAuth.createUserWithEmailAndPassword(email, password).catch((error) => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
}).then(() => {
const user = fbAuth.currentUser;
db.ref('/users/' + user.uid).set({
username: userData.username,
displayName: userData.displayName,
uid: user.uid
})
dispatch(isAuthed());
}).catch((error) => {
console.warn('Error in createUser callback', error)
});
}
}
const initialState = {
isAuthed: false,
isAuthenticating: false
};
export default function authentication (state = initialState, action) {
console.log(action)
switch (action.type) {
case AUTHENTICATING :
return {
...state,
isAuthenticating: true
}
case NOT_AUTHED :
return {
isAuthenticating: false,
isAuthed: false
}
case IS_AUTHED :
return {
isAuthenticating: false,
isAuthed: true
}
default :
return state
}
};
有沒有人得到了一個類似的問題?我在我的createUser函數中使用了console.log,並且它甚至沒有到達那裏,我認爲這很奇怪。還有在我嘗試運行函數動作之前已經定義好了。真的不知道我在做什麼錯:(
你從哪裏 –
調用'createUser'? @JoshKelley我從'〜/ redux/modules/authentication''中導入了createUser,而不是從'〜/ redux/modules/authentication''中導入{createUser};該死......感謝提示! – maxwellgover