Skip to content

Commit

Permalink
fix: prevent the use of onChangeText on the initial render (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorrmon authored Jul 13, 2023
1 parent 0ba50f8 commit 267a018
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/components/MaskedTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export const MaskedTextInputComponent: ForwardRefRenderFunction<
const [maskedValue, setMaskedValue] = useState(initialMaskedValue)
const [unMaskedValue, setUnmaskedValue] = useState(initialUnMaskedValue)
const [rawValue, setRawValue] = useState(initialRawValue);
const [isInitialRender, setIsInitialRender] = useState(true)

const actualValue = pattern || type === "currency" ? maskedValue : rawValue;

function onChange(value: string) {
Expand All @@ -85,6 +87,11 @@ export const MaskedTextInputComponent: ForwardRefRenderFunction<
}

useEffect(() => {
if (isInitialRender) {
setIsInitialRender(false)
return
}

onChangeText(maskedValue, unMaskedValue)
}, [maskedValue, unMaskedValue])

Expand Down

0 comments on commit 267a018

Please sign in to comment.