# use-backdrop

> React Hooks API for quickly displaying full-screen backdrops/overlays

Latest version **1.0.12** (published 2021-07-14) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.12 |
| Published | 2021-07-14 |
| First published | 2020-07-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 239.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | adrioalimin |
| Keywords | react, hook, backdrop, browser, fullscreen, simple, alert, modal |

## Links

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

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

- 1.0.12 (latest) — 2021-07-14
- 1.0.11 — 2021-07-14
- 1.0.10 — 2021-07-14
- 1.0.9 — 2021-05-22
- 1.0.8 — 2021-05-01
- 1.0.7 — 2021-04-30
- 1.0.6 — 2021-04-30
- 1.0.5 — 2021-04-30
- 1.0.4 — 2021-04-29
- 1.0.3 — 2021-04-29
- 1.0.2 — 2021-04-29
- 1.0.1 — 2020-08-23
- 1.0.0 — 2020-07-27
- 0.2.1 — 2020-07-21
- 0.2.0 — 2020-07-11
- … 9 more at https://npm.io/package/use-backdrop/versions

## README

React Hooks API for quickly displaying customizable full-screen backdrops/overlays.

Think of use-backdrop as `alert()`, but native to React, and endlessly customizable!

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

### use-backdrop is ready for production apps 😘

![gif of use-backdrop](https://raw.githubusercontent.com/lyulka/use-backdrop/master/use-backdrop-demo-compressed.gif)

## Install

```bash
npm install --save use-backdrop
```

## Usage

🎉 A no-fuss example that uses `use-backdrop` to display a modal is available on [GitHub](https://github.com/lyulka/use-backdrop). 🎉

### Step 1: Wrap BackdropProvider around your root (App) component

```jsx
import { BackdropProvider } from 'use-backdrop';
 
return (
  <BackdropProvider>
    <div className="App">
      { /* The rest of your app. */ }
    </div>
  </BackdropProvider>
)
```

### Step 2: Import and call the useBackdrop hook

```jsx
import { useBackdrop } from 'use-backdrop';
 
export default function MyComponent() {
  const { displayBackdrop, closeBackdrop } = useBackdrop();
}
```


### Step 3: Call displayBackdrop, passing in a render function
```jsx
export default function MyComponent() {
  const { displayBackdrop } = useBackdrop();
 
  const handleClick = () => displayBackdrop((closeBackdrop) => (
    <div>
      <button onClick={closeBackdrop}>
        Click me to close the backdrop.
      </button>
    </div>
  ));
 
  return (
    <div>
      <button onClick={handleClick}>
        Click me to display a backdrop.
      </button>
    </div>
  )
}
```

### BackdropProvider props & options

```js
BackdropProvider.propTypes = {
  children: PropTypes.element,

  // zIndex of the backdrop surface. Unused if backdropSurface is
  // overridden.
  zIndex: PropTypes.number,

  // If true, backdrop background is transparent.
  disableDarken: PropTypes.bool,

  // A render function: (children) => (/* React Component */)
  // that returns a Component that overrides (takes the place of)
  // the default darkened div background.
  //
  // See /example/src/ExampleApp.jsx for proper use.
  backdropSurface: PropTypes.func
}

BackdropProvider.defaultProps = {
  children: null,
  disableBackdrop: false,
  zIndex: 10,
  backdropSurface: null
}
```

## License

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

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