What is a prompt in React Native?
A prompt is a dialog that asks the user to type a value — a name, a password, a note — and returns it. The web has window.prompt; React Native has Alert.prompt, but only on iOS. On Android you roll your own with a Modal.
iOS — Alert.prompt
One call, native look, iOS only:
import { Alert } from 'react-native';
function askName() {
// iOS ONLY — Alert.prompt does not exist on Android
Alert.prompt(
'Your name',
'What should we call you?',
(text) => console.log('entered:', text),
'plain-text', // or 'secure-text' for a password field
'', // default value
);
}Cross-platform — Modal prompt
Works on iOS and Android identically. Drive it with a visible flag and callbacks:
import { useState } from 'react';
import { Modal, Pressable, Text, TextInput, View } from 'react-native';
function Prompt({ visible, title, onSubmit, onCancel }) {
const [text, setText] = useState('');
return (
<Modal visible={visible} transparent animationType="fade" onRequestClose={onCancel}>
<View style={{ flex: 1, justifyContent: 'center', backgroundColor: '#00000066', padding: 24 }}>
<View style={{ backgroundColor: '#fff', borderRadius: 14, padding: 20 }}>
<Text style={{ fontSize: 17, fontWeight: '600', marginBottom: 12 }}>{title}</Text>
<TextInput
autoFocus
value={text}
onChangeText={setText}
style={{ borderWidth: 1, borderColor: '#e5e7eb', borderRadius: 8, padding: 12, fontSize: 16 }}
/>
<View style={{ flexDirection: 'row', justifyContent: 'flex-end', gap: 16, marginTop: 16 }}>
<Pressable onPress={onCancel}><Text style={{ color: '#6b7280', fontSize: 16 }}>Cancel</Text></Pressable>
<Pressable onPress={() => onSubmit(text)}>
<Text style={{ color: '#2563eb', fontSize: 16, fontWeight: '600' }}>OK</Text>
</Pressable>
</View>
</View>
</View>
</Modal>
);
}Props (cross-platform prompt)
| Prop | Type | Default | Description |
|---|---|---|---|
| visible | boolean | false | Shows/hides the prompt. |
| title | string | — | Question shown above the input. |
| onSubmit | fn(text) | — | Called with the entered value on OK. |
| onCancel | fn | — | Called on Cancel and Android back. |
| secureTextEntry | boolean | false | Pass to TextInput for a password prompt. |
Gotchas
Alert.promptis iOS only. Calling it on Android does nothing — use the Modal version for cross-platform.- Reset the input state when the Modal closes, or the previous value shows up next time it opens.
- Set
onRequestCloseon the Modal so the Android back button cancels the prompt. - Use
autoFocusso the keyboard opens with the dialog — otherwise the user taps twice.
FAQ
Does React Native have a prompt? Yes on iOS (Alert.prompt), no on Android — build a Modal prompt for both.
How do I make a password prompt? Pass 'secure-text' to Alert.prompt, or secureTextEntryto the Modal’s TextInput.