OTP

The Otp component allows you to implement a One-Time Password (OTP) verification UI. With the customUIRender prop, you can fully customize the look and behavior of the OTP interface to match your project's needs.

Installation Method

You can use the following command to install the extension with the latest plugins:

npx @akinon/projectzero@latest --plugins

Props

Prop
Type
Required
Description

customUIRender

React.ReactNode

Optional

A render function to override the default OTP interface. Provides access to UI and control handlers

submitAction

SubmitHandler<{ [key: string]: any }>

Yes

A submit handler function triggered when OTP form is submitted.

data

{ [key: string]: any }

Yes

Data object containing required fields like phone number. OTP code will be appended here before submission

CustomUIRender Parameters

Parameter
Type
Description

closeHandler

() => void

Closes the popup manually.

resendHandler

() => void

Triggers OTP resend functionality.

onSubmit

(event: FormEvent<HTMLFormElement>) => Promise<void>

Form submit function that wraps validation and calls submitAction.

otp

string

Current OTP value in the input field.

setOtp

(otp: string) => void

Updates the OTP input value.

hasError

boolean

Whether the current OTP input has a validation error.

error

string

Error message for invalid OTP attempts.

canResend

boolean

Indicates whether the resend option is enabled.

time

number

Countdown in seconds for the resend option.

codeLength

number

Expected number of digits in the OTP input.

setHasError

(hasError: boolean) => void

Allows toggling of error state manually.

Usage Example

Default Usage

Customizing OTP

Last updated

Was this helpful?