Skip to content

Commit dc42eba

Browse files
update readme
1 parent a4d2762 commit dc42eba

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

readme.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,66 @@ A simple react hook to create otp inputs with ease. Inspired by libraries like r
3030
npm i react-otp-input-hook
3131
```
3232

33+
34+
35+
## Usage
36+
37+
```
38+
import { useOtpInput } from "react-otp-input-hook";
39+
40+
const BasicOTPComponent = ({ onChange }: { onChange: (val: string) => void }) => {
41+
const { register } = useOtpInput({
42+
onInputValueChange: onChange,
43+
});
44+
45+
const defaultOptions = { required: true };
46+
47+
return (
48+
<div style={{ padding: '10px' }}>
49+
<input {...register("digit-1", defaultOptions)} />
50+
<input {...register("digit-2", defaultOptions)} />
51+
<input {...register("digit-3", defaultOptions)} />
52+
<input {...register("digit-4", defaultOptions)} />
53+
<input {...register("digit-5", defaultOptions)} />
54+
</div>
55+
);
56+
};
57+
```
58+
59+
## Use Inside any form
60+
```
61+
function App() {
62+
const [value, setValue] = useState("");
63+
64+
return (
65+
<div>
66+
<form
67+
onSubmit={(e) => {
68+
e.preventDefault();
69+
console.log('Value', value);
70+
}}
71+
>
72+
73+
<BasicOTPComponent
74+
onChange={(value: any) => {
75+
console.log(value);
76+
setValue(value);
77+
}}
78+
/>
79+
80+
<button
81+
type="submit"
82+
>
83+
Submit
84+
</button>
85+
</form>
86+
87+
<div>{value}</div>
88+
</div>
89+
);
90+
}
91+
```
92+
3393
<center>
3494
<img width="100%" alt="Basic component output" src="https://raw.githubusercontent.com/supercoder123/react-otp-input-hook/main/images/basic-component.gif" />
3595
</center>

0 commit comments

Comments
 (0)