1

So i'm new to React Native but every time i put a new Component like a Button or an Image from Facebooks React Native Doc's i keep getting a "ReferenceError : Can't Find Variable" error on the simulator? This honestly happens when i add any other piece of code other than Text. Am i not linking something incorrectly? Anything would help.

/**
 * 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,
  },
});

**ERROR This is the error

4
  • 3
    Text and View were imported from react-native, why hasn't Button been imported from anywhere? Commented Nov 10, 2017 at 21:33
  • Sorry for my ignorance but does every component have to be listed under the import list? Commented Nov 10, 2017 at 21:46
  • 1
    No worries, yeah, everything you want to use in a given file needs to either be imported from somewhere else or declared somehow before it is used. Commented Nov 10, 2017 at 21:57
  • 1
    Oh i see, yeah it's starting to work now! Commented Nov 10, 2017 at 22:05

2 Answers 2

4

Try adding Button to the import like so:

import {
  Platform,
  StyleSheet,
  Text,
  View,
  Button
} from 'react-native';
Sign up to request clarification or add additional context in comments.

Comments

0

You can use Touchable Opacity instead of button, Its very efficient way inside that you can add Text and also the on click functions too.....

<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>`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.