0.1.0 • Published 1 year ago

modal-state v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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
  },
});