With this module you can use input masks, it provides ready-to-use masks, in the brazilian standard
npm i react-mask-brasil
import { useMask } from "react-mask-brasil"
export default () => {
//In useMask you will specify the mask through a string
let [cpf, setCpf] = useMask('CPF')
return (
<div>
<input
type="text"
value={cpf}
onChange={setCpf}
/>
</div>
)
}
| Type | Mask |
|---|---|
| CPF | 999.999.999-99 |
| CNPJ | 88.888.888/8888-88 |
| CPF_CNPJ | 999.999.999-99 or 99.999.999/9999-99 |
Note: use the type as a string, example: 'CPF'
You can also get the input value in number format, just request the third item of the array in useMask, useful for storing in a database
let [cpf, setCpf, dataCpf] = useMask('CPF')