导入函数时出现“不是函数”错误

3
这可能是一个简单的引用/绑定错误,但我似乎无法弄清楚:
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中正确读取了signOut,这是auth文件夹中acions.js的导入。然而,home中来自action.js的getToken函数未被识别,这是从home文件夹导入的。 我做了完全相同的事情,并检查了所有对这些js文件、目录以及函数输出的引用。 有什么想法吗?

1个回答

0

你的getToken缺少一个映射,就像你为signOut所做的一样:

export default connect(null, { signOut, getToken })(Home);
//                                    ^^^^^^^^^^-- added this

这样,this.props.getToken 应该在 Home 内部可用。


啊,对了,我完全忘记了!非常感谢! - Ray Jonathan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接