我正在從RecommendationItemActions.js
操作文件中的所有操作接收到Actions may not have an undefined "type" property. Have you misspelled a constant?
錯誤。操作可能沒有未定義的「type」屬性 - React-Native/Redux
出現此問題與包含在這兩個出口。
import firebase from 'firebase';
import {} from 'redux-thunk';
import {
RECOMMENDATION_ITEM_UPDATE,
RECOMMENDATION_ITEMS_FETCH_SUCCESS
} from './types';
export const recommendationItemUpdate = ({ prop, value }) => {
//ex. Want to change name? Send in prop [name] and value [ what you want the new name to be ]
return {
type: RECOMMENDATION_ITEM_UPDATE,
payload: { prop, value }
};
};
export const recommendationItemsFetch =() => {
const { currentUser } = firebase.auth();
return (dispatch) => {
firebase.database().ref(`/users/${currentUser.uid}/recommendationItems`)
//snapshot is the value found
//snapshot is an object that describes what data is there
.on('value', snapshot => {
console.log(snapshot.val());
dispatch({
type: RECOMMENDATION_ITEMS_FETCH_SUCCESS,
payload: snapshot.val()
});
//snapshot.val() is the actual data at snapshot
});
};
};
這些types
的進口type.js
文件
export const RECOMMENDATION_ITEMS_FETCH_SUCCESS = 'recommendation_items_fetch_success';
export const RECOMMENDATION_ITEM_UPDATE = 'recommendation_item_update';
的行動是在actions
文件夾
export * from './RecommendationItemActions';
他們的RecommendationItemCreate.js
文件中導入通過index.js
文件導出中明確規定
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Text, Image, View } from 'react-native';
import { recommendationItemUpdate, recommendationItemCreate } from '../../actions';
import { CardSection, Input, Button } from './../common';
import GooglePlacesAutocomplete from './../googlePlaces/GooglePlacesAutocomplete';
而且我Input
組件
<Input
label="ADDRESS"
placeholder="Address"
value={this.props.formattedAddress}
onChangeText={
value => this.props.recommendationItemUpdate({ prop: 'formattedAddress', value })
}
/>
我找不到這將導致Actions may not have an undefined "type" property
,現在已經被敲我的頭這幾天任何錯誤的onChangeText
內引用。明確定義了type
,並且可以在整個使用過程中準確追蹤。
最接近的參考實測值 React+Redux - Uncaught Error: Actions may not have an undefined 「type」 property
這仍然是無益的。這裏是我的createStore作爲參考:
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import firebase from 'firebase';
import ReduxThunk from 'redux-thunk';
import reducers from './reducers';
import Router from './Router';
class App extends Component {
componentWillMount() {
const config = {
REMOVED FOR EXAMPLE
};
firebase.initializeApp(config);
}
render() {
const store = createStore(reducers, {}, applyMiddleware(ReduxThunk));
//applyMiddleware is a store-enhancer - it adds additional functionality
//to store
return (
<Provider store={store}>
<Router />
</Provider>
);
}
}
export default App;
嘿尼克,感謝您的回答。這無法解決我遇到的問題,但我很欣賞你的迴應。實際問題最終成爲我的減速器中的一個不正確的參考。我在RecommendationItemsList.js文件中導出了具有與我的參考相對比的不正確鍵的RecommendationItemReducer。 – DJSrA