# @jiayangbot/use-modal

> Simple way to control your modal

Latest version **1.0.0** (published 2023-03-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jiayangbot/use-modal
pnpm add @jiayangbot/use-modal
yarn add @jiayangbot/use-modal
bun add @jiayangbot/use-modal
```

## 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 | 1.0.0 |
| Published | 2023-03-23 |
| First published | 2023-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 1 |
| Unpacked size | 30.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | jiayangbot |
| Maintainers | jiayangbot |

## Links

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

## Dependencies (1)

- [valtio](https://npm.io/package/valtio.md) ^0.5.2

## Recent versions

- 1.0.0 (latest) — 2023-03-23

## README

# @jiayangbot/use-modal

> Simple way to control modal

[![NPM](https://img.shields.io/npm/v/@jiayangbot/use-modal.svg)](https://www.npmjs.com/package/@jiayangbot/use-modal) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm install --save @jiayangbot/use-modal
```

## Usage

### Call function
in Modal.js
```tsx
import { closeModal, useModal } from '@jiayangbot/use-modal'

const Modal = () => {
  const { open, data } = useModal('modal_name')

  if (!open) return null
  return (
    <div>
      {/* modal content */}
      <Button onClick={() => closeModal('modal_name')}>close</Button>
    </div>
  )
}

export default Modal
```

in somewhere
```tsx
import { openModal } from '@jiayangbot/use-modal'

openModal('modal_name')
```

### use InitModal
in MyModal.js
```tsx
import { closeModal, useModal, initModal } from '@jiayangbot/use-modal'

export const MyModal = initModal('modal_name')

const Modal = () => {
  const { open, data } = MyModal.useModal()

  if (!open) return null
  return (
    <div>
      {/* modal content */}
      <Button onClick={() => MyModal.close()}>close</Button>
    </div>
  )
}

export default Modal
```

in somewhere
```tsx
import { MyModal } from 'path/MyModal.js'

MyModal.open({ data:['a'] })
```

## License

MIT

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