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

0.0.3 • Public • Published

React-Sync-Modal-State

Synchronous Modal state for react

Usage

npm install react-sync-modal-state

Example

/*
  function useSyncModalState<T = any>(): {
    value: boolean;
    openModal: () => Promise<T | null>;
    closeModal: (returnValue: T) => void;
  }
*/
import { useSyncModalState } from "react-sync-modal-state";

const App = () => {
  const modalState = useSyncModalState();

  return (
    <>
      <div>
        <button
          onClick={async () => {
            const data = await modalState.openModal();
            console.log("This was called after modal was closed", { returnData: data });
          }}
        >
          Open Modal
        </button>

        {modalState.value && (
          <div>
            modal opened{" "}
            <button
              onClick={async () => {
                modalState.closeModal({ test: "123" });
                console.log("Modal Closed");
              }}
            >
              close
            </button>
          </div>
        )}
      </div>
    </>
  );
};

Resource:

Package Sidebar

Install

npm i react-sync-modal-state

Weekly Downloads

15

Version

0.0.3

License

MIT

Unpacked Size

6.39 kB

Total Files

7

Last publish

Collaborators

  • iambpn