# use-modal-hook

> React hook for controlling modal components

Latest version **2.1.2** (published 2022-11-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-modal-hook
pnpm add use-modal-hook
yarn add use-modal-hook
bun add use-modal-hook
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2022-11-06 |
| First published | 2019-04-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 69 |
| Author | alexander.khivrych |
| Maintainers | alexander.khivrych |
| Keywords | react, use-modal, react-modal-hook, hook, react-hooks, modal, modal-hook, use-modal-hook, useModal |

## Links

- npm: https://www.npmjs.com/package/use-modal-hook
- Repository: https://github.com/alexanderkhivrych/use-modal-hook
- Homepage: https://github.com/alexanderkhivrych/use-modal-hook#readme
- Issues: https://github.com/alexanderkhivrych/use-modal-hook/issues
- npm.io page: https://npm.io/package/use-modal-hook

## Dependencies (3)

- [react](https://npm.io/package/react.md) ^18.2.0
- [react-dom](https://npm.io/package/react-dom.md) ^18.2.0
- [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

- 2.1.2 (latest) — 2022-11-06
- 2.1.1 — 2022-09-10
- 2.1.0 — 2022-09-09
- 1.0.19 — 2021-04-29
- 1.0.18 — 2020-02-22
- 1.0.17 — 2019-06-19
- 1.0.16 — 2019-06-19
- 1.0.15 — 2019-06-19
- 1.0.14 — 2019-05-21
- 1.0.13 — 2019-04-13
- 1.0.12 — 2019-04-13
- 1.0.11 — 2019-04-13
- 1.0.10 — 2019-04-13
- 1.0.9 — 2019-04-11
- 1.0.8 — 2019-04-08
- … 8 more at https://npm.io/package/use-modal-hook/versions

## README

<div align="center">
  <h1>
    <br/>
      use-modal-hook ❤️
    <br />
  </h1>
    <sup>
    <br />
    <br />
    <a href="https://github.com/alexanderkhivrych/use-modal-hook/pulls" target="_blank">
      <img src="https://img.shields.io/badge/PRs-welcome-green.svg" alt="PRs welcome" />
    </a>
    <a href="https://www.npmjs.com/package/use-modal-hook" target="_blank">
      <img src="https://img.shields.io/npm/v/use-modal-hook.svg" alt="npm package" />
    </a>
    <a href="https://www.npmjs.com/package/use-modal-hook" target="_blank">
      <img src="https://img.shields.io/npm/dm/use-modal-hook.svg" alt="npm downloads" />
    </a>
    <a href="https://github.com/alexanderkhivrych/use-modal-hook" target="_blank">
      <img src="https://img.shields.io/badge/Maintained%3F-yes-green.svg?style=flat-square" alt="Maintenance" />
    </a>
  </sup>
</div>

> React hook for controlling modal components

## Install

```bash
#With npm
npm install use-modal-hook --save 
```

```bash
#With yarn
yarn add use-modal-hook
```

## Usage
[![Edit react use modal hook example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/2zz9w1pwrr?fontsize=14)
```jsx
import React, { memo } from "react";
import { useModal, ModalProvider } from "use-modal-hook";
import Modal from "react-modal"; // It can be any modal

const MyModal = memo(
  ({ isOpen, onClose, title, description, closeBtnLabel }) => (
    <Modal isOpen={isOpen} onRequestClose={onClose}>
      <h2>{title}</h2>
      <div>{description}</div>
      <button onClick={onClose}>{closeBtnLabel}</button>
    </Modal>
  )
);

const SomePage = memo(() => {
  const [showModal, hideModal] = useModal(MyModal, {
    title: "My Test Modal",
    description: "I Like React Hooks",
    closeBtnLabel: "Close"
  });

  return (
    <>
      <h1>Test Page</h1>
      <button onClick={showModal}>Show Modal</button>
    </>
  );
});

const App = () => (
  <ModalProvider>
    <SomePage />
  </ModalProvider>
);

```

#### `useModal(<ModalComponent: Function|>, <modalProps: Object>, <onClose: Function>): [showModal: Function, hideModal: Function]`
Param | Type  | Description
--- | --- | ---
ModalComponent | `Function` | It can be any [`react`](https://reactjs.org/docs/react-api.html) component that you want to use for show modal
modalProps | `Object` | Props that you want to pass to your modal component
showModal | `Function` | It is function for show your modal, you can pass any dynamic props to this function
hideModal | `Function` | It is function for hide your modal, you can pass any dynamic props to this function
onClose | `Function` | It callback will be triggered after modal window closes

#### `showModal(dynamicModalProps: Object)`
Param | Type  | Description
--- | --- | ---
dynamicModalProps | `Object` | Dynamic props that you want to pass to your modal component

## License

MIT © [alexanderkhivrych](https://github.com/alexanderkhivrych)

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