New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-native-input-otp

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-input-otp

A fully customizable, one-time password (OTP) input component for smartphones built with React Native.

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
0
Created
Source

react-native-input-otp

Overview

react-native-input-otp is a fully customizable, one-time password (OTP) input component designed for React Native applications. This package makes it easy to integrate an OTP input feature into your mobile app, ensuring a user-friendly and secure way for users to input their OTP codes.

Installation

To install react-native-input-otp, run the following command in your React Native project:

npm install react-native-input-otp

Props

The OtpInput component accepts several props to customize its behavior and style:

Prop NameTypeDescriptionDefault Value
numInputsnumberThe number of input boxes for the OTP.4
onChange(otp: string) => voidFunction called with the OTP value when it changes.-
isDisabledbooleanIf set to true, all input boxes are disabled.false
autoFocusbooleanIf set to true, the first input box is focused automatically.false
keyboardTypeKeyboardType (React Native)The type of keyboard to display for inputs.'default'
valuestringThe current value of the OTP input.'' (empty string)
containerStyleViewStyle (React Native style)Custom styles for the container of the input boxes.-
inputStyleTextStyle (React Native style)Custom styles for each input box.-
onUserFocusFunctionTriggered onFocus for user end-

Customization

You can customize the appearance of the OTP inputs by providing containerStyle and inputStyle props. These props accept standard React Native style objects.

Usage

In Class Components

First, import the OtpInput component from the package:

import OtpInput from 'react-native-input-otp';

Then, you can use the OtpInput component in your class component as follows:

import React, { Component } from 'react';
import { View } from 'react-native';
import OtpInput from 'react-native-input-otp';

class YourComponent extends Component {
  handleOtpChange = otp => {
    console.log(otp); // OTP value
  };

  render() {
    return (
      <View>
        <OtpInput numInputs={4} onChange={this.handleOtpChange} />
      </View>
    );
  }
}

export default YourComponent;

In Functional Components

For functional components, the usage is similar. Import the OtpInput component and use it inside your functional component:

import React from 'react';
import { View } from 'react-native';
import OtpInput from 'react-native-input-otp';

const YourComponent = () => {
  const handleOtpChange = otp => {
    console.log(otp); // OTP value
  };

  return (
    <View>
      <OtpInput numInputs={4} onChange={handleOtpChange} />
    </View>
  );
};

export default YourComponent;

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

react-native

FAQs

Package last updated on 09 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts