Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native - Unable to create text input

I am trying to create a text input element but the it keeps throwing out error saying "Can't Find Variable: TextInput" even though I copied the code from their getting started page.

Code:

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

and the image of error attached. enter image description here

like image 389
ksa_coder Avatar asked Jul 02 '15 20:07

ksa_coder


People also ask

How do I disable TextInput in React Native?

To disable options on React Native TextInput, we can set the editable and selectTextOnFocus props to false . to set them both to false . Then we won't see any popup options displayed when we focus on the text input. editable set to false disables typing in the input.

How do I use onSubmitEditing React Native?

onSubmitEditing is triggered when you click the text input submit button (keyboard button). onChangeText is triggered when you type any symbol in the text input. In your example, you will achieve what you need in both cases.


1 Answers

You need to initialize TextInput with the rest of the react-native components as follows:

var {
  TextInput,
  AppRegistry,
  StyleSheet,
  Text,
  View,
} = React;
like image 118
Pavan Ravipati Avatar answered Oct 09 '22 21:10

Pavan Ravipati