Skip to content

Commit 827497d

Browse files
authored
Merge pull request #6 from tea-lover-418/feat/add-onCompleted-support
feat: added onCompleted support
2 parents 1d9c946 + e2600ff commit 827497d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/index.tsx

Lines changed: 9 additions & 3 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,
21-
onChange,
22+
onChange = () => {},
23+
onCompleted = () => {},
2224
placeholder = '·',
2325
value: pValue,
2426
}: Props) => {
@@ -137,7 +139,11 @@ const ReactInputVerificationCode = ({
137139
}, []);
138140

139141
React.useEffect(() => {
140-
onChange(value.join(''));
142+
const stringValue = value.join('');
143+
const isCompleted = !stringValue.includes(placeholder);
144+
145+
if (isCompleted) onCompleted(stringValue);
146+
onChange(stringValue);
141147
}, [value]);
142148

143149
React.useEffect(() => {

0 commit comments

Comments
 (0)