1.0.6 • Published 3 years ago

react-otp-ui v1.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

react-otp-ui

One-time password input component for React.

How to Install

Make sure you have Node.js and NPM installed.

npm install react-otp-ui

Or

yarn add react-otp-ui

How to Use

import React from 'react'
import OtpForm from 'react-otp-ui'

const OTPDemo = () => {
  const handleOnChange = (data) => {
    console.log('data', data)
    
    /* data object like this {digit: '1', digit2: '2', digit3: '3', digit4: '4', otpValue: '1234'} */
  }

  return (
    <OtpForm
      onChange={handleOnChange}
    />
  )
}

Demo

OTP Demo

Check out Online Demo here.

import React from 'react'
import OtpForm from 'react-otp-ui'

const OTPDemoAdvanced = () => {
  const handleOnChange = (data) => {
    console.log('data', data)
  }

  return (
    <OtpForm
      onChange={handleOnChange}
      numberOfInputs={6}
      showSeparator
      separtor=":"
      secureInput
    />
  )
}

Available Props

Prop NameTypeDefault ValueDescription
classNameString''className for input to add custom styles
disabledBooleanfalseIt will disable the inputs to enter values
numberOfInputsNumber4Length of OTP value to capture from user
onChangeFunctionnullCallback function to get the entered OTP value
secureInputBooleanfalseTo render the inputs like password fields
separatorString-Text to show in separator between inputs
showSeparatorBooleanfalseFlag to show separator between inputs