Skip to content

Latest commit

 

History

History
62 lines (38 loc) · 1.28 KB

README.md

File metadata and controls

62 lines (38 loc) · 1.28 KB

react-native-use-otp-verify

Wrapper Hook for react-native-otp-verify

Make yourself familiar with react-native-otp-verify before using this hook .

Installation

yarn add react-native-otp-verify @monadstech/react-native-use-otp-verify

or

npm i react-native-otp-verify @monadstech/react-native-use-otp-verify

then Follow instruction of react-native-otp-verify first

Usage

Basic Example

import React from 'react';
import {useOtpVerify} from '@monadstech/rn-use-otp-verify';

const OtpConfirm = () => {
  const [otp, setOtp] = React.useState('');
  const [autoDetectedOtp, autoDetectError] =  useOtpVerify() ;

  React.useEffect(() => {
    if (autoDetectedOtp) {
      setOtp(autoDetectedOtp);
    }
  }, [autoDetectedOtp, handleLogin]);

  ...
};

OTP Parser

Default otpParser checks for following regex : /(\d+)[\s]is|is[\s](\d+).?/g

i.e. otp SMS must be one of following formats

  • .... OTP is 2098 ....

  • .... 2098 is OTP ....

However, you can pass a custom otpParser to useOtpVerify hook.

this otpParser must accept sms as argument and return otp as string or empty string.

LICENSE

MIT LICENSE