Package Exports
- react-simple-modal-controller
- react-simple-modal-controller/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-simple-modal-controller) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
react-simple-modal-controller
Installation
npm install react-simple-modal-controller
Setting
Wrap the top folder with a provider. that's all!
import ModalProvider from "react-simple-modal-controller";
const App = () => {
return <ModalProvider>...</ModalProvider>;
};
Usage
basic modal
const openModal = () => {
modal.open(ModalComponent, { title: "test" });
};
const Page = () => {
return <button onClick={openModal}>modal open</button>;
};
const ModalComponent = ({ title }: { title: string }) => {
return (
<div className="modal">
<h2>{title}</h2>
<button onClick={modal.close}>ok</button>
<button onClick={modal.close}>cancel</button>
<button onClick={openModal}>nesting modal open</button>
</div>
);
};
async modal
const openAsyncModal = async () => {
try {
const response = await modal.openAsync<UserConsentResponse>(AsyncModalComponent, {
userId: 123,
});
if(response) {
...
} else {
...
}
} catch (error) {
...
}
};
const Page = () => {
return <button onClick={openAsyncModal}>
asyncModal open
</button>
};
const TestAsyncModal = ({ resolve, userId }: { resolve: ModalResolver<string>; userId: number }) => {
return (
<div className="modal">
<h2>{title}</h2>
<button
onClick={async () => {
const response = await getUserConsent(userId);
resolve(response);
}}
>
ok
</button>
<button
onClick={() => {
reject(null);
modal.close();
}}
>
cancel
</button>
</div>
);
};