React Native Onkeypress Event Example

Apr 02, 2021 . Admin

Hi Guys,

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

, after I will using onkeypress event using onKeyPress attitude add in tag react native.

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

Step 1 - Create project

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

expo init Onkeypress 
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 , Text} from 'react-native';

export default class ButtonBasics extends Component {
  _writeText() {

  render() {
    return (
      <View style={styles.container}>
        <View style={styles.buttonContainer}>
          placeholder="Type here!"
        <Text style={styles.textinfo}>
          React Native onKeyPress Event Example

const styles = StyleSheet.create({
  container: {
   flex: 1,
   justifyContent: 'center',
   backgroundColor: '#000',
  buttonContainer: {
    margin: 15,
    width: 320,
   justifyContent: 'center',
    fontSize: 25,
    marginTop: 20,
    marginLeft: 20,
    textAlign: 'center', 
    borderWidth: 2,
    padding: 10,
    borderRadius: 5,
    borderColor: '#ffffff'
Step 3 - Run project

In the last step run your project using bellow command.

expo start

It will help you...

#React Native