A customizable OTP input component for React Native with TypeScript support, enabling seamless user authentication with flexible input handling and cross-platform compatibility.
npm install @codsod/react-native-otp-input
bash
npm install @codsod/react-native-otp-input
`
Complete Example:
`javascript
import React, { useState } from "react";
import OTPInput from "@codsod/react-native-otp-input";
import { StyleSheet, Text, View } from "react-native";
const Home = () => {
const [otp, setOTP] = useState("");
return (
length={4}
onOtpComplete={(txt: string) => setOTP(txt)}
inputStyle={styles.otpInput}
/>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
otpInput: {
backgroundColor: "blue",
color: "white",
width: 60,
height: 60,
fontSize: 20,
},
});
export default Home;
`
Props
| Prop | Type | Description | Default |
| --------------- | ---------- | ------------------------------------------------------------------------- | ------- |
| length | number | The number of input fields for the OTP. | 4 |
| onOtpComplete | Function | Callback fired when the OTP input is complete, receiving the entered OTP. | - |
| style | style | Custom styles for the OTP container. | - |
| inputStyle | style` | Custom styles for each input field. | - |