This package provides a React component, `<MaskedInput>`, for creating input fields that enforce specific formatting patterns on user input. It is part of the larger `text-mask` ecosystem, which offers similar masking solutions for various JavaScript frameworks and vanilla JS. The current stable version for `react-text-mask` is 5.5.0. Releases are typically driven by fixes and minor enhancements across its different framework-specific packages (e.g., React, Vue, Angular), rather than a fixed cadence. A key differentiator is its highly configurable `mask` prop, which accepts an array of characters and regular expressions, allowing for flexible pattern definition. It also supports a `render` prop for advanced customization, enabling integration with styled-components or other custom input wrappers. It aims for full compatibility with standard HTML `<input>` attributes like `className`, `placeholder`, `onBlur`, and `onChange`, simplifying its adoption into existing forms.
npm install react-text-maskVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of `MaskedInput` for phone number formatting, including placeholder, guide, and event handlers.
Set `guide={false}` on the `MaskedInput` component.Ensure `mask` is an array, e.g., `mask={['(', /[1-9]/, ..., ')']}`. For complex dynamic masks, you can provide a function that returns a mask array.The `mask` prop must be an array of characters and/or regular expressions, or a function that returns such an array. Wrap the mask pattern in an array, e.g., `mask={['(', /[1-9]/, /\d/, /\d/, ')']}`.Allow `react-text-mask` to manage the input's value. Use the `onChange` event handler to retrieve the formatted or raw value, but avoid setting the `value` prop after initial mount unless implementing complex controlled component logic with careful state synchronization.
Ensure the `mask` prop is either an array (e.g., `['a', 'b', 'c']`) or a function that returns an array or `false`. This error often occurs if `mask` is `undefined`, `null`, or an incorrect primitive type.