# use-imask

> React hook that exposes [IMask](https://github.com/uNmAnNeR/imaskjs) object

Latest version **2.0.0** (published 2021-09-09) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2021-09-09 |
| First published | 2021-05-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 1 |
| Unpacked size | 19.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | tracksuitdev |
| Maintainers | tracksuitdev |
| Keywords | react, imask, hooks, masked input |

## Links

- npm: https://www.npmjs.com/package/use-imask
- Homepage: https://github.com/tracksuitdev/use-imask#readme
- npm.io page: https://npm.io/package/use-imask

## Dependencies (1)

- [imask](https://npm.io/package/imask.md) ^6.2.0

## 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

- 2.0.0 (latest) — 2021-09-09
- 1.0.1 — 2021-06-05
- 1.0.0 — 2021-05-28

## README

# use-imask ![npm](https://img.shields.io/npm/v/use-imask)  ![npm bundle size](https://img.shields.io/bundlephobia/minzip/use-imask) ![NPM](https://img.shields.io/npm/l/use-imask)
React hook that exposes [IMask](https://github.com/uNmAnNeR/imaskjs) object

## Installation

```bash
npm install use-imask
```

or if you use yarn

```bash
yarn add use-imask
```

## Usage

```typescript jsx
const maskOptions = { mask: Number }; // make sure options don't change on each render (use constant or useMemo or ref)

function Example() {
  const [value, setValue] = useState("");

  const [ ref ] = useIMask(maskOptions, {
  // use onAccept callback instead of onChange to change value
    onAccept: e => { 
      setValue(e.target.value);
    },
  });

  return (
    <input ref={ref} value={value} />
  );
}
```

## Props
|name|type|description|
|---|---|---|
|options|\<M extends AnyMaskedOptions\>|mask options, when options change updateOptions function is called by the IMask object
|onAccept|(e: ChangeEvent\<E\>, mask: InputMask\<M\> \| undefined) => void|function called on IMask accept event
|onComplete|(e: ChangeEvent\<E\>, mask: InputMask\<M\> \| undefined) => void|function called on IMask complete event

## Return value

|name|type|description|
|---|---|---|
|ref|RefObject\<HTMLInputElement\|null\>|apply this to your input element
|maskRef|RefObject\<InputMask\<M\> \| undefined\>|ref with IMask object

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