0

I have been trying to make chips of the input on pressing "enter" by user. How could I achieve that in react-native environment? I am trying to use "onKeyPress" event but not providing solution.

Here is my code:

<Input style={formCSS.textFieldInput} onKeyPress={(keyPress) => console.log(keyPress)} placeholder='Hobbies' />

Picture of desired result

enter image description here

1 Answer 1

2

According to doc, onKeyPress

Callback that is called when a key is pressed. This will be called with { nativeEvent: { key: keyValue } } where keyValue is 'Enter' or 'Backspace' for respective keys and the typed-in character otherwise including ' ' for space. Fires before onChange callbacks. Note: on Android only the inputs from soft keyboard are handled, not the hardware keyboard inputs.

So you should use it like

onKeyPress={(e) => console.log(e.nativeEvent.key)}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.