React Native 引用错误:找不到变量

1cklez4t  于 2023-10-22  发布在  React
关注(0)|答案(2)|浏览(181)

所以我是React Native的新手,但是每次我从Facebook React Native Doc中放置一个新的组件,比如Button或Image,我都会得到一个“ReferenceError:模拟器上出现“找不到变量”错误?当我添加除Text之外的任何其他代码时,都会发生这种情况。我是不是搞错了什么?什么都行。

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';

import {
  Platform,
  StyleSheet,
  Text,
  View
} from 'react-native';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

export default class App extends Component<{}> {
  render() {
    return (
        <View style={styles.container}>
        
        <Text style={styles.welcome}>
          This is a new App!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit App.js
        </Text>
        <Text style={styles.instructions}>
          {instructions}
        </Text>
        <Button
  onPress={onPressLearnMore}
  title="Learn More"
  color="#841584"
  accessibilityLabel="Learn more about this purple button"
/>
        <Text style={{color: 'blue'}}>Hello</Text>
      </View>
        
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'white',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

**错误This is the error

fnx2tebb

fnx2tebb1#

尝试将Button添加到导入中,如下所示:

import {
  Platform,
  StyleSheet,
  Text,
  View,
  Button
} from 'react-native';
ql3eal8s

ql3eal8s2#

您可以使用触摸不透明度,而不是按钮,它非常有效的方式内,您可以添加文本,也点击功能太.....

<TouchableOpacity onPress={() => { KeyCheck() }}>
    <LinearGradient useAngle={true} angle={45} angleCenter={{ x: 0.5, y: 0.5 }}
        colors={['#1ac6ff', '#00ace6', '#0083b0']}
        start={{ x: 0, y: 0.5 }}
        end={{ x: 1, y: 0.5 }}
        style={styles.submitbtn}>
            <Text style={[styles.starttxt, { fontSize: Commonwidth(15), alignSelf: "center" }]}>
                    {"Submit"}
            </Text>
    </LinearGradient>
</TouchableOpacity>`

相关问题