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

0.1.0 • Public • Published

Modal State

Getting Started

You can use this react hook to control your modal more easily. It provides a better code representation of modal state, which is useful when you are managing multiple modals. Also you can attach callbacks for every action of modal, like opening and closing of modal.

Installation

To install and set up the library, run:

npm install -S modal-state

Or if you prefer using Yarn:

yarn add --dev modal-state

How to use

const Component = () => {
  const modal = useModal();

  return (
    <body>
      <button onClick={modal.open}>Open modal</button>
      <Modal isOpen={modal.isOpen} onClose={modal.close}></Modal>
    </body>
  );
};

Attach callbacks

const modal = useModal({
  onClose: () => {
    //gets executed when modal is closed
  },
  onOpen: () => {
    //gets executed when modal is opened
  },
});

Dependents (0)

Package Sidebar

Install

npm i modal-state

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

4.95 kB

Total Files

8

Last publish

Collaborators

  • alitoshmatov