Categories
JavaScript Answers React Native Answers

How to get the value in TextInput when onBlur is called with React Native?

Spread the love

Sometimes, we want to get the value in TextInput when onBlur is called with React Native.

In this article, we’ll look at how to get the value in TextInput when onBlur is called with React Native.

How to get the value in TextInput when onBlur is called with React Native?

To get the value in TextInput when onBlur is called with React Native, we can get the value from the onEndEditing callback.

For instance, we write:

import * as React from 'react';
import { TextInput, View } from 'react-native';
import Constants from 'expo-constants';
import { Card } from 'react-native-paper';

export default function App() {
  return (
    <View style={{ padding: 30 }}>
      <TextInput
        onEndEditing={(e) => console.log(e.nativeEvent.text)}
        placeholder="Name"
      />
    </View>
  );
}

to set onEndEditing to (e) => console.log(e.nativeEvent.text) after we press enter.

Conclusion

To get the value in TextInput when onBlur is called with React Native, we can get the value from the onEndEditing callback.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *