Skip to content

Commit 1ef3ec6

Browse files
committed
fix: add default for onCompleted and onChange
1 parent 451a793 commit 1ef3ec6

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/index.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ type Props = {
1919

2020
const ReactInputVerificationCode = ({
2121
length = 4,
22-
onChange,
23-
onCompleted,
22+
onChange = () => {},
23+
onCompleted = () => {},
2424
placeholder = '·',
2525
value: pValue,
2626
}: Props) => {
@@ -141,11 +141,9 @@ const ReactInputVerificationCode = ({
141141
React.useEffect(() => {
142142
const stringValue = value.join('')
143143

144-
if (typeof onChange === "function") {
145-
onChange(stringValue);
146-
}
144+
onChange(stringValue);
147145

148-
if (!stringValue.includes(placeholder) && typeof onCompleted === "function") {
146+
if (!stringValue.includes(placeholder)) {
149147
onCompleted(stringValue)
150148
}
151149
}, [value]);

0 commit comments

Comments
 (0)