2015-07-02 25 views
5

Próbuję utworzyć element wprowadzania tekstu, ale ciągle wyskakuje komunikat "Can not find Variable: TextInput", mimo że skopiowałem kod z ich strony początkowej.React Native - Nie można utworzyć wpisu tekstowego

Kod:

/** 
* Sample React Native App 
* https://github.com/facebook/react-native 
*/ 
'use strict'; 

var React = require('react-native'); 
var { 
    AppRegistry, 
    StyleSheet, 
    Text, 
    View, 
} = React; 

var AwesomeProject = React.createClass({ 
    render: function() { 
    return (
     <View style={styles.container}> 
     <Text style={styles.welcome}> 
      My App Name 
     </Text> 
     <TextInput 
      style={{height: 40, borderColor: 'gray', borderWidth: 1}} 
      onChangeText={(text) => this.setState({input: text})} 
     /> 
    <Text>{'user input: ' + this.state.input}</Text> 
     </View> 
    ); 
    } 
}); 

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

AppRegistry.registerComponent('AwesomeProject',() => AwesomeProject); 

a obraz błędu załączeniu. enter image description here

Odpowiedz

20

Trzeba zainicjować TextInput z resztą składników reagujących-rodzimy następująco:

var { 
    TextInput, 
    AppRegistry, 
    StyleSheet, 
    Text, 
    View, 
} = React; 
+0

Wystarczy dodać na to: jeśli zapomniałeś importować TextInput w innym pliku (słownie AnotherThing.js), który jest importowany do App.js, błąd będzie wyglądać tak, jakby pochodził z App.js, nawet jeśli pochodzi on z AnotherThing.js – nemicolopterus

Powiązane problemy