Skip to content

Commit 451a793

Browse files
committed
feat: added onCompleted support
1 parent 1d9c946 commit 451a793

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ const KEY_CODE = {
1111

1212
type Props = {
1313
length?: number;
14-
onChange: (data: string) => any;
14+
onChange?: (data: string) => any;
15+
onCompleted?: (data: string) => any;
1516
placeholder?: string;
1617
value?: string;
1718
};
1819

1920
const ReactInputVerificationCode = ({
2021
length = 4,
2122
onChange,
23+
onCompleted,
2224
placeholder = '·',
2325
value: pValue,
2426
}: Props) => {
@@ -137,7 +139,15 @@ const ReactInputVerificationCode = ({
137139
}, []);
138140

139141
React.useEffect(() => {
140-
onChange(value.join(''));
142+
const stringValue = value.join('')
143+
144+
if (typeof onChange === "function") {
145+
onChange(stringValue);
146+
}
147+
148+
if (!stringValue.includes(placeholder) && typeof onCompleted === "function") {
149+
onCompleted(stringValue)
150+
}
141151
}, [value]);
142152

143153
React.useEffect(() => {

0 commit comments

Comments
 (0)