react-modal-pirate
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

react-modal-pirate

A react-modal wrapper that makes it (even) easier to create a modal.

NPM JavaScript Style Guide

Install

yarn add react-modal-pirate

or

npm install --save react-modal-pirate

Usage

  1. Wrap your application with
import ModalProvider from "react-modal-pirate"

const App = () => {
  return (
    <ModalProvider>
      <Main/>
    </ModalProvider>
  )
}
  1. Create the modal content
import {useClose} from "react-modal-pirate"

const Modal = () => {
  const closeModal = useClose();

  return (
    <div>
      <h1>Hello World</h1>
      <button onClick={closeModal}>Exit</button>
    </div>
  )
}

Note: Modals also close by pressing the Esc key or by clicking outside the modal itself, so it is not mandatory to use the useClose hook.

  1. Open the modal using useOpen hook
import { useOpen } from "react-modal-pirate"
import Modal from "./Modal"

const Main = () => {
  const openModal = useOpen()

  return (
    <button onClick={() => openModal(<Modal/>)}>Open Modal</button>
  )
}

License

MIT © alexnix

Readme

Keywords

none

Package Sidebar

Install

npm i react-modal-pirate

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

24.2 kB

Total Files

15

Last publish

Collaborators

  • alexnix