This is an illustration of a PinInput component.
import { PinInput, PinInputField } from "@/components/ui/pin-input"
function Example() {
return (
<PinInput noOfFields={4}>
{Array.from({ length: 4 }).map((_, index) => (
<PinInputField key={index} index={index} />
))}
</PinInput>
)
}

Installation

Run the following command:

npx gluestack-ui add pin-input

API Reference

To use this component in your project, include the following import statement in your file.
import { PinInput, PinInputField } from "@/components/ui/pin-input"
export default () => (
<PinInput>
<PinInputField />
</PinInput>
)

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

PinInput

It inherits all the properties of react-native's View component on native and html div tag on web.
Prop
Type
Default
Description
value
string
The value to be used in the pin input. This is the value that will be returned on form submission.
onChange
(value: string) => void
Function called when the value of the pin input is changed.
onComplete
(value: string) => void
Function called when the last pin input is filled.

PinInputField

It inherits all the properties of of react-native's TextInput component on native and html input tag on web.

Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

PinInput with caption

This is an example of a PinInput component with a caption.
import {
FormControl,
FormControlLabel,
FormControlLabelText,
} from "@/components/ui/form-control"
import { PinInput, PinInputField } from "@/components/ui/pin-input"
function App() {
const [value, setValue] = useState("")
useEffect(() => {
console.log(value)
}, [value])
return (
<FormControl className="gap-4">
<FormControlLabel>
<FormControlLabelText>Enter OTP</FormControlLabelText>
</FormControlLabel>
<PinInput value={value} onChange={setValue} numberOfFields={4}>
{Array.from({ length: 4 }).map((_, index) => (
<PinInputField key={index} index={index} />
))}
</PinInput>
</FormControl>
)
}