我在PatientQueue.js文件中有一个类组件作为PatientQueue,在PatientDetailView.js文件中有PatientDetailView的另一个类组件。 我正在调用PatientDetailView类的PatientQueue类中的Getdetails()函数,方法是创建其对象。但是当我打电话给Getdetails时,我得到了可能的无用承诺拒绝(id:0)的错误:
TypeError:this.props未定义。
PatientQueue文件
import React from 'react';
import { FlatList, BackHandler, ListView, ToastAndroid, ScrollView, ActivityIndicator,AppState, TouchableOpacity, Alert, StyleSheet, Image, Text, View, Button, AsyncStorage, SafeAreaView, RefreshControl } from 'react-native';
import { createStackNavigator, createAppContainer, DrawerItems } from 'react-navigation';
import { SearchBar, Icon } from 'react-native-elements';
import MultiSelect from 'react-native-multiple-select';
import { PatientDetailView } from './PatientDetailView';
import { connect } from "react-redux";
import { fetchQueue } from '../common/actions/patientQueue';
import { filterQueue } from '../common/actions/filters';
import { clearAllFilters } from '../common/actions/filters';
class PatientQueue extends React.Component {
constructor(props) {
super(props);
...
}
ForTesting(){
console.log("function called")
}
async Getdetails() {
console.log("fetch detailssss")
const retrievedItem = await AsyncStorage.getItem("StorageData");
const getretrievedItem = JSON.parse(retrievedItem);
var loginToken = getretrievedItem.token;
await this.props.dispatch(fetchQueue(loginToken));
console.log("fetch details comleted")
}
render() {
...
}
}
export default connect(mapStateToProps)(PatientQueue);
const RefreshList = new PatientQueue();
export { RefreshList }
PatientDetailView文件
import React from 'react';
import { FlatList,Modal, ListView,TextInput, Linking,Picker,
TouchableOpacity, ActivityIndicator, Alert, StyleSheet, Text, View, Button, AsyncStorage } from 'react-native';
import { createStackNavigator, createAppContainer } from 'react-navigation';
import { Header, Left, Right, Icon, Container, Body, Title } from 'native-base';
import {RefreshList} from './PatientQueue';
import PatientQueue from './PatientQueue';
class PatientDetailView extends React.Component {
constructor(props) {
super(props);
this.state = {
modalVisible: false,
TransferModalVisible:false,
...
}
}
async OpenUhs(BtnStatus,PatientId) {
RefreshList.Getdetails();
this.props.navigation.navigate("Queue")
}
render() {
...
}
export { PatientDetailView };