这可能是一个简单的引用/绑定错误,但我似乎无法理解:
import React from 'react';
var { View, StyleSheet, Alert, AsyncStorage } = require('react-native');
import {Button} from 'react-native-elements'
import {Actions} from 'react-native-router-flux';
import {connect} from 'react-redux';
import styles from "./styles"
import { actions as auth} from "../../../auth/index"
import { actions as home } from "../../index";
import { user } from '../../../auth/scenes/Login/index';
const { getToken } = home;
const { signOut } = auth;
class Home extends React.Component {
constructor(){
super();
this.state = { }
this.onSignOut = this.onSignOut.bind(this);
this.onShowData = this.onShowData.bind(this);
}
onSignOut() {
this.props.signOut(this.onSuccess.bind(this), this.onError.bind(this))
}
onSuccess() {
Actions.reset("Auth")
}
onError(error) {
Alert.alert('Oops!', error.message);
}
onShowData(){
AsyncStorage.getItem("userData").then((value) => {
this.props.getToken(value); //THIS LINE IS GIVING THE ERROR
alert(value);
Actions.pop();
});
}
render() {
return (
<View style={styles.container}>
<Button
raised
borderRadius={4}
title={'LOG OUT'}
containerViewStyle={[styles.containerView]}
buttonStyle={[styles.button]}
textStyle={styles.buttonText}
onPress={this.onSignOut}/>
<Button
borderRadius={4}
title={'Show Data'}
containerViewStyle={[styles.showDataButton]}
buttonStyle={[styles.button]}
textStyle={styles.buttonText}
onPress={this.onShowData}/>
</View>
);
}
}
export default connect(null, { signOut })(Home);
奇怪的是,注销是从auth正确读取的,auth是从acions导入的。auth文件夹的js。但是,getToken函数无法从主页识别,这是一个操作。js从主文件夹导入。
我以完全相同的方式做了这两件事,并检查了对这些js文件、目录以及函数导出的所有引用。
有什么想法吗?