首页 > 解决方案 > 即使我没有使用它,也无法在 react-native 中找到变量错误

问题描述

所以我正在学习 React-Native 并且我创建了一个之前已经工作过的抽屉。但是经过一些不涉及 Drawer 的修改后,Can't find variable: Contact即使我没有导入名为Contact.

抽屉.js

import React, { Component } from 'react';
import { Text, View } from 'react-native';
import { DrawerNavigator, DrawerItems } from 'react-navigation';
import ButtonScreen from '../screens/ButtonScreen';
import Contacts from '../screens/Contacts';
import Information from '../screens/Information';
import Preferences from '../screens/Preferences';

const Drawer = new DrawerNavigator({
    Home: {
        screen: ButtonScreen,
        navigationOptions: {
            drawerLabel: 'Button'
        },
    },
    Contacts: {
        screen: Contacts,
    },
    Preferences: {
        screen: Preferences,
    },  
    Info: {
        screen: Information,
    }
}, {
    contentComponent: (props) => (
        <View>
            <Text>Custom Header</Text>
            <DrawerItems {...props}/>
            <Text>Custom Footer</Text>
       </View>
    )
});

export default Drawer;

联系人.js

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { View, Text } from 'react-native';

class Contacts extends Component {
     constructor(props) {
         super(props);
     }

    render() {
        return (
            <View>
                <Text>
                    Contact Component
                </Text>
            </View>
        );
    }
}

const mapStateToProps = (state) => {
    const { isDrawerOpened } = state;
    return { isDrawerOpened };
}

export default connect(mapStateToProps)(Contacts);

通过堆栈跟踪,错误来自抽屉.js 第 6 行,我在其中导入Contacts而不是Contact. 我已经跑去npm start -- --reset-cache看看它是否能解决它,但没有。我很困惑为什么会这样。

标签: javascriptreactjsreact-native

解决方案


推荐阅读