TextInput is a core React Native component used to accept user input through the keyboard. It supports text, numbers, passwords, email inputs, and more across Android and iOS.
useStateThe TextInput component works by binding its value to a state variable and updating that value using onChangeText.
// Import TextInput and useState hook
import React, { useState } from "react";
import { TextInput, View } from "react-native";
const App = () => {
const [text, setText] = useState("");
return (
<View>
<TextInput
value={text}
onChangeText={setText}
placeholder="Enter text here"
/>
</View>
);
};
export default App;
As the user types inside the input box, the state variable updates instantly, keeping the UI and data in sync.
Use the simulator below to understand how secureTextEntry and State binding work in React Native. Notice that even if the text is hidden (dots), the State variable holds the real data.
// TextInput with secure password entry
<TextInput
secureTextEntry={true}
placeholder="Enter password"
/>
keyboardType for better UX