bhrott / react-native-masked-text

A pure javascript masked text and input text component for React-Native.
MIT License
1.61k stars 249 forks source link

CPF, CNPJ, and Zip-Code mask don't work #180

Closed akinncar closed 5 years ago

akinncar commented 5 years ago

When I try to use cpf and cnpj mask on react-native 0.60, my screen don't render without errors. In the same input, if I try to use cel-phone or only-numbers mask, it works. Somebody have idea to solve or maybe has been through it???

I'm using react-native-masked-text: 1.12.4

bhrott commented 5 years ago

Hi, please provide a code sample.

akinncar commented 5 years ago

I was copying my code to provide and I found my error, the default state of value provide in Input was false, but the correct is "", look:

Simplify Code

Wrong:

import { InputMask } from "react-native-masked-text";

const [registerNumber, setRegisterNumber] = useState(false);  // error here

<InputMask
      mask="cpf"
      keyboardType="numeric"
      placeholder={`Digite seu CPF`}
      value={registerNumber}
      onChangeText={setRegisterNumber}
/>

Correct:

import { InputMask } from "react-native-masked-text";

const [registerNumber, setRegisterNumber] = useState("");  // solve here

<InputMask
      mask="cpf"
      keyboardType="numeric"
      placeholder={`Digite seu CPF`}
      value={registerNumber}
      onChangeText={setRegisterNumber}
/>