michael_vons
michael_vons

Reputation: 1060

How to get input value from react-native-element

In React Native 16.

Get input value

<Input
 ...
 onChange={event => getValue(event)}
 />

Output value

const getValue = event => {
   console.log(event.nativeEvent.text);
 };

Upvotes: 0

Views: 4516

Answers (2)

Vikram Biwal
Vikram Biwal

Reputation: 2826

Set value to the state.

const getValue = event => {
   this. setState({text: event.nativeEvent.text});
 };

Upvotes: 0

Muhammed Anees
Muhammed Anees

Reputation: 1850

The Input component from react-native-elements is basically rendering the TextInput component. So you can use onChangeText instead of onChange like

import React, { Component } from 'react';
import { Input } from 'react-native-elements';

export default function UselessTextInput() {
  const [value, onChangeText] = React.useState('Useless Placeholder');

  return (
    <Input
      onChangeText={text => onChangeText(text)}
      value={value}
    />
  );
}

Hope this helps

Upvotes: 5

Related Questions