I am working on an app for a company. I want the TextInput to trigger a function after the user adds their text and presses enter on TextInput
Any help would be greatly appreciated.
I am working on an app for a company. I want the TextInput to trigger a function after the user adds their text and presses enter on TextInput
Any help would be greatly appreciated.
You can handle onKeyPress to do that.
import React, { Component } from 'react'; import { TextInput } from 'react-native'; export default function UselessTextInput() { const handleOnKeyPress = event =>{ const key = event.nativeEvent.key // As I remember key for enter button is "Enter", but if not you can console.log(key) and hit enter to check the value if(key ==="Enter"){ //do you stuff here } } return ( <TextInput onKeyPress={handleOnKeyPress} /> ); } You can use onSubmitEditing for executing your function on enter or submit a button from the keyboard.
https://reactnative.dev/docs/textinput#onsubmitediting
import React, { Component } from 'react'; import { TextInput } from 'react-native'; export default function UselessTextInput() { const executeOnEnter=()=>{ alert('hi i am pressed') } return ( <TextInput onSubmitEditing={executeOnEnter} /> ); }