react-native-otp-textinput and react-native-otp-verify serve distinct but complementary roles in React Native OTP implementations. react-native-otp-textinput is a customizable UI component for rendering and managing OTP input fields, handling focus transitions and styling across digits. react-native-otp-verify is a native module that leverages Android's SMS Retriever API to automatically read OTP messages containing a specific app hash, eliminating manual entry on Android devices. Neither package replaces the other—they address different layers of the OTP experience: user interface versus system-level message interception.
When implementing one-time password (OTP) flows in React Native apps, developers face two distinct challenges: collecting user input and automatically reading OTPs from SMS messages. The packages react-native-otp-textinput and react-native-otp-verify address these problems in fundamentally different ways — one is a UI component, the other is a native bridge for SMS reading. Confusing them leads to architectural mismatches. Let’s clarify their roles and how they fit into real-world authentication flows.
react-native-otp-textinput is a pure JavaScript UI component that renders a series of text inputs for OTP entry. It handles focus management, styling, and input masking but has no awareness of SMS or device capabilities.
// react-native-otp-textinput: Rendering OTP fields
import OTPTextInput from 'react-native-otp-textinput';
function OTPScreen() {
const handleOTPSubmit = (code) => {
// Validate code against your backend
console.log('User entered:', code);
};
return (
<OTPTextInput
handleTextChange={handleOTPSubmit}
inputCount={6}
containerStyle={{ marginTop: 20 }}
textInputStyle={{ borderWidth: 1, borderRadius: 8 }}
/>
);
}
react-native-otp-verify is a native module that interacts with Android’s SMS Retriever API to automatically read OTP messages without requiring SMS permissions. It provides no UI — only methods to start/stop listening for messages containing a specific hash.
// react-native-otp-verify: Reading OTP from SMS
import { getOtp, addListener } from 'react-native-otp-verify';
async function setupAutoRead() {
try {
// Start listening for SMS with your app's hash
await getOtp();
// Handle received OTP
addListener((otp) => {
console.log('Auto-read OTP:', otp);
// Pass to your validation logic
});
} catch (error) {
console.warn('SMS auto-read failed:', error);
}
}
⚠️ Critical Note:
react-native-otp-verifyonly works on Android and requires your backend to include a 11-character hash in OTP messages. iOS support is not possible due to platform restrictions.
In a production app, you’ll often use both packages together:
react-native-otp-verify to auto-fill the OTP when possible (Android only).react-native-otp-textinput for manual entry (all platforms).Here’s how they integrate:
import React, { useState, useEffect } from 'react';
import OTPTextInput from 'react-native-otp-textinput';
import { getOtp, removeListener } from 'react-native-otp-verify';
function AuthScreen() {
const [otp, setOtp] = useState('');
useEffect(() => {
// Try auto-read on mount (Android only)
const setupAutoRead = async () => {
try {
await getOtp();
// Listener would update `otp` state when SMS arrives
} catch (e) {
// Silently fail – user will enter manually
}
};
setupAutoRead();
return () => removeListener(); // Cleanup
}, []);
const handleSubmit = (code) => {
// Validate OTP (whether auto-filled or manual)
console.log('Validating:', code || otp);
};
return (
<OTPTextInput
handleTextChange={setOtp}
inputCount={6}
// Pre-fill if auto-read succeeded
textInputProps={{ value: otp }}
/>
);
}
react-native-otp-textinput: Works identically on iOS and Android since it’s pure JS.react-native-otp-verify: Android-only (relies on SMS Retriever API). Fails silently on iOS.react-native-otp-textinput: Zero native setup. Just install and use.react-native-otp-verify: Requires:
react-native-otp-textinput: Handles input errors via props like tintColor for invalid states.react-native-otp-verify: Throws errors if:
react-native-otp-textinput if:react-native-otp-verify if:Myth: "react-native-otp-verify replaces OTP input fields."
Reality: It only provides the OTP string. You still need a UI component (like react-native-otp-textinput) to display it or handle manual entry.
Myth: "Both packages work on iOS."
Reality: Apple’s privacy restrictions prevent automatic SMS reading. react-native-otp-verify will throw an error on iOS.
Myth: "I don’t need backend changes for auto-read."
Reality: Without the 11-character hash in your SMS, react-native-otp-verify won’t detect messages.
react-native-otp-verify stops listening after 5 minutes. Restart if needed.| Aspect | react-native-otp-textinput | react-native-otp-verify |
|---|---|---|
| Type | UI Component | Native Module |
| Platform Support | iOS + Android | Android Only |
| Backend Changes | None | Requires SMS hash |
| Permissions | None | None (uses Play Services) |
| Primary Role | Collect user input | Auto-read SMS OTP |
| UI Included? | Yes | No |
These packages solve complementary problems, not competing ones. Think of react-native-otp-textinput as your OTP keyboard and react-native-otp-verify as your OTP clipboard reader. In most real-world apps, you’ll wire them together: auto-fill the clipboard when possible, but always keep the keyboard ready for manual entry. Ignoring this distinction leads to either broken Android flows or unnecessary complexity on iOS.
Choose react-native-otp-textinput when you need a cross-platform, customizable UI component for OTP entry that works consistently on both iOS and Android. It’s ideal for projects where you control the frontend but can’t modify backend SMS templates to include app-specific hashes, or when you prioritize a consistent manual input experience across all devices.
Choose react-native-otp-verify when building Android-focused applications that require seamless OTP auto-reading without SMS permissions, provided your backend can append the required 11-character hash to SMS messages. Avoid it for iOS-only projects or if you cannot implement the necessary backend changes for hash generation.
React Native Component that can used for OTPs and Pins as secure pin input.
npm i -S react-native-otp-textinput

Check the Example react native app for usage.
Supports both Android and iOS.
The following props are applicable for the component along with props supported by react native TextInput component
| Prop | Type | Optional | Default | Description |
|---|---|---|---|---|
| defaultValue | string | Yes | '' | Default Value that can be set based on OTP / Pin received from parent container. |
| handleTextChange | func | No | n/a | callback with concated string of all cells as argument. |
| handleCellTextChange | func | Yes | n/a | callback for text change in individual cell with cell text and cell index as arguments |
| inputCount | number | Yes | 4 | Number of Text Input Cells to be present. |
| tintColor | string | Yes | #3CB371 | Color for Cell Border on being focused. |
| offTintColor | string | Yes | #DCDCDC | Color for Cell Border Border not focused. |
| inputCellLength | number | Yes | 1 | Number of character that can be entered inside a single cell. |
| containerStyle | object | Yes | {} | style for overall container. |
| textInputStyle | object | Yes | {} | style for text input. |
| testIDPrefix | string | Yes | 'otpinput' | testID prefix, the result will be otp_input_0 until inputCount |
| autoFocus | bool | Yes | false | Input should automatically get focus when the components loads |
| onBlur | func | Yes | n/a | Callback that is called when the text input is blurred. |
| onFocus | func | Yes | n/a | Callback that is called when the text input is focused. |
| disabled | func | Yes | false | To disable the input |
Clearing and Setting values to component
// using traditional ref
clearText = () => {
this.otpInput.clear();
}
setText = () => {
this.otpInput.setValue("1234");
}
render() {
return (
<View>
<OTPTextInput ref={e => (this.otpInput = e)} >
<Button title="clear" onClick={this.clearText}>
</View>
);
}
// hooks
import React, { useRef } from 'react';
const ParentComponent = () => {
let otpInput = useRef(null);
const clearText = () => {
otpInput.current.clear();
}
const setText = () => {
otpInput.current.setValue("1234");
}
return (
<View>
<OTPTextInput ref={e => (otpInput = e)} >
<Button title="clear" onClick={clearText}>
</View>
);
}
If you think I have helped you, feel free to get me coffee. 😊