0

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.

1
  • Do you have any code to show? Something for us to reproduce? I can understand if you can't because this is for a business. Commented Jun 24, 2020 at 2:08

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! I really appreciate this. I had no idea how to go about it.
I am glad it helped. If it really help you, please considering about accept my answer.
Actually, that did not work. Check out this post stackoverflow.com/questions/50584382/…
1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.