React Native OnChange Event Example Tutorial.

React Native

Nicesnippets

182

13-07-2020


Hi Guys,

In this blog, I will explain you how to use on change event in react native. You can easily use on change event in react native. First i will create new fuction _onPressButton

, after I will using on change event using onChange attitude add in tag react native.

Here, I will give you full example for simply display on change event using react native as bellow.

Step 1 - Create project

In the first step Run the following command for create project.

expo init onChange

Step 2 - App.js

In this step, You will open App.js file and put the code.

import React, { Component } from 'react';

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

export default class Home extends Component {

_onPressButton() {

alert('You type in text box')

}

render() {

return (

<View style={styles.buttonContainer}>

<TextInput

style={{height: 40}}

placeholder="Type here!"

autoFocus={true}

onChange={this._onPressButton}

/>

</View>

);

}

}

const styles = StyleSheet.create({

container: {

flex: 1,

justifyContent: 'center',

},

buttonContainer: {

margin: 80

}

});

Step 3 - Run project

In the last step run your project using bellow command.

npm start

Output

It will help you...