# react-imask

> React input mask

Latest version **7.6.1** (published 2024-05-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-imask
pnpm add react-imask
yarn add react-imask
bun add react-imask
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 7.6.1 |
| Published | 2024-05-21 |
| First published | 2017-11-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 121.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5183 |
| Author | Alexey Kryazhev |
| Maintainers | unmanner |
| Keywords | react, imask, input, mask |

## Links

- npm: https://www.npmjs.com/package/react-imask
- Repository: https://github.com/uNmAnNeR/imaskjs.git#master
- Homepage: https://imask.js.org/
- Issues: https://github.com/uNmAnNeR/imaskjs/issues
- npm.io page: https://npm.io/package/react-imask

## Dependencies (2)

- [imask](https://npm.io/package/imask.md) ^7.6.1
- [prop-types](https://npm.io/package/prop-types.md) ^15.8.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 7.6.1 (latest) — 2024-05-21
- 7.5.1-alpha.0 (next) — 2024-03-20
- 6.0.0-alpha.0 (beta) — 2019-12-17
- 7.6.0 — 2024-04-09
- 7.5.0 — 2024-02-28
- 7.4.0 — 2024-02-08
- 7.3.1-alpha.0 — 2024-01-31
- 7.3.0 — 2023-12-25
- 7.2.1 — 2023-12-18
- 7.2.0 — 2023-12-13
- 7.1.3 — 2023-07-18
- 7.1.2 — 2023-07-12
- 7.1.1 — 2023-07-11
- 7.1.0-alpha.2 — 2023-07-11
- 7.1.0-alpha.1 — 2023-07-11
- … 78 more at https://npm.io/package/react-imask/versions

## README

# React IMask Plugin
react-imask

[![npm version](https://badge.fury.io/js/react-imask.svg)](https://badge.fury.io/js/react-imask)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

<a href="https://opencollective.com/imask/donate" target="_blank">
  <img src="https://opencollective.com/imask/donate/button.png?color=blue" width=300 />
</a>

## Install
`npm install react-imask`

## Mask Input Example
```javascript
import { useRef } from 'react';
import { IMaskInput } from 'react-imask';

// use ref to get access to internal "masked = ref.current.maskRef"
const ref = useRef(null);
const inputRef = useRef(null);
<IMaskInput
  mask={Number}
  radix="."
  value="123"
  unmask={true} // true|false|'typed'
  ref={ref}
  inputRef={inputRef}  // access to nested input
  // DO NOT USE onChange TO HANDLE CHANGES!
  // USE onAccept INSTEAD
  onAccept={
    // depending on prop above first argument is
    // `value` if `unmask=false`,
    // `unmaskedValue` if `unmask=true`,
    // `typedValue` if `unmask='typed'`
    (value, mask) => console.log(value)
  }
  // ...and more mask props in a guide

  // input props also available
  placeholder='Enter number here'
/>
```

## Extend Existing Components
```javascript
import { IMaskMixin } from 'react-imask';

// extend style component
const StyledInput = styled.input`
  color: green;
`;

const MaskedStyledInput = IMaskMixin(({inputRef, ...props}) => (
  <StyledInput
    {...props}
    innerRef={inputRef}  // bind internal input (if you use styled-components V4, use "ref" instead "innerRef")
  />
));

<MaskedStyledInput
  mask={Number}
  radix="."
  onAccept={(value, mask) => console.log(value)}
  // ...and more mask props in a guide

  // ...other styled props
/>
```
More options see in a [guide](https://imask.js.org/guide.html).

## Using hook
```javascript
import { useState } from 'react';
import { useIMask } from 'react-imask';

function IMaskWithHook () {
  const [ opts, setOpts ] = useState({ mask: Number });
  const {
    ref,
    maskRef,
    value,
    setValue,
    unmaskedValue,
    setUnmaskedValue,
    typedValue,
    setTypedValue,
  } = useIMask(opts, /* optional {
    onAccept,
    onComplete,
    ref,
    defaultValue,
    defaultUnmaskedValue,
    defaultTypedValue,
  } */);
  
  return (
    <input ref={ref} />
  );
}
```

---
_Source: https://npm.io/package/react-imask · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
