use-mask-input is a React hook library providing flexible input masking capabilities for various form libraries and plain HTML inputs. It currently stands at version 3.9.0 and receives active development, with minor releases adding features like new mask aliases and integrations, and patch releases for optimizations and bug fixes. Key differentiators include out-of-the-box support for popular form libraries such as React Hook Form, TanStack Form, and Ant Design, as well as a rich set of built-in mask aliases for common patterns like Brazilian banking information, CPF, CNPJ, currency, email, and date/time. The library focuses on providing a performant and developer-friendly API through custom hooks and higher-order functions, ensuring seamless integration into modern React applications. It primarily targets client-side usage within a React context.
npm install use-mask-inputVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `use-mask-input` with React Hook Form to apply phone and email masks to input fields. It shows the `useHookFormMask` hook in action, enabling masked input with form validation and submission.
Upgrade to `use-mask-input@^3.0.0` or later. Check the official documentation for specific migration guides if upgrading from a very old version.
Ensure components wrapped with `withMask` or `withHookFormMask` are also wrapped with `React.memo`, e.g., `const MyMaskedInput = React.memo(withMask(MyInput));`
Change your import statements from `import { useMaskInputAntd } from 'use-mask-input';` to `import { useMaskInputAntd } from 'use-mask-input/antd';`.Refer to the TanStack Form usage example in the documentation, specifically how `inputProps` are destructured and passed to the input element: `const inputProps = maskField(mask, { name: field.name, value: field.state.value, onBlur: field.handleBlur, onChange: (event) => field.handleChange(event.target.value) });`Ensure all `use-mask-input` hooks are called within the top-level of a React functional component or within another custom hook.
Upgrade your React and React DOM packages to version 17 or higher: `npm install react@^17 react-dom@^17`.
Verify that `use-mask-input` is correctly installed. Check your import paths. If the issue persists, ensure your bundler supports sub-path exports from `package.json` or explicitly configure it.