Gathering detailed insights and metrics for react-promiseportal
Gathering detailed insights and metrics for react-promiseportal
Gathering detailed insights and metrics for react-promiseportal
Gathering detailed insights and metrics for react-promiseportal
npm install react-promiseportal
Typescript
Module System
Node Version
NPM Version
TypeScript (57.97%)
JavaScript (42.03%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4 Stars
27 Commits
1 Watchers
9 Branches
1 Contributors
Updated on Mar 10, 2023
Latest Version
1.4.0
Package Id
react-promiseportal@1.4.0
Unpacked Size
16.42 kB
Size
4.89 kB
File Count
6
NPM Version
6.7.0
Node Version
11.15.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
11
1
19
Promise portals for React
Using npm:
$ npm install react-promiseportal
Using yarn:
$ yarn add react-promiseportal
Then with a module bundler like webpack, use as you would anything else:
1// Using ES6 Modules 2import { usePromisePortal } from 'react-promiseportal'; 3// using CommonJS modules 4const usePromisePortal = require('react-promiseportal').usePromisePortal;
Normally when managing a modal, or similar hierarchy agnostic elements, it is common practice to render these in the component, and control them with local boolean state.
For example:
1// App.js 2import React from 'react'; 3 4function App() { 5 const [isOpen, setOpen] = React.useState(false); 6 return ( 7 <> 8 <button onClick={() => setOpen(true)}>Click me to open a modal</button> 9 <SomeModalComponent open={isOpen}> 10 <button 11 onClick={() => { 12 alert('You confirmed!'); 13 setOpen(false); 14 }} 15 > 16 Confirm 17 </button> 18 <button 19 onClick={() => { 20 alert('You cancelled.'); 21 setOpen(false); 22 }} 23 > 24 Cancel 25 </button> 26 </SomeModalComponent> 27 </> 28 ); 29}
In large components, managing several modals with different isOpen
state can be confusing.
With react-promiseportal
, I offer complete co-location.
At the top-level of your application, import the PromisePortalProvider
module.
1// AppContext.js 2import React from 'react'; 3import { PromisePortalProvider } from 'react-promiseportal'; 4 5function AppContext() { 6 return ( 7 <PromisePortalProvider> 8 <App /> 9 </PromisePortalProvider> 10 ); 11}
You can then import usePromisePortal
(hook) or withPromisePortal
(hoc).
1// App.js 2import React from 'react'; 3import { usePromisePortal } from 'react-promiseportal'; 4 5function App() { 6 const portal = usePromisePortal(); 7 return ( 8 <button 9 onClick={async () => { 10 const didConfirm = await portal((onConfirm, onCancel) => { 11 return ( 12 <SomeModalComponent open> 13 <button onClick={onConfirm}>Confirm</button> 14 <button onClick={onCancel}>Cancel</button> 15 </SomeModalComponent> 16 ); 17 }); 18 19 if (didConfirm) alert('You confirmed!'); 20 else alert('You cancelled.'); 21 }} 22 > 23 Click me to open a modal 24 </button> 25 ); 26}
Calling onConfirm
with an Event or a falsy value, will resolve the promise with the value true
.
If called with a truthy value, like an object, this is returned instead.
For example, if the Modal
were instead a form, which returned some input for a request:
1// App.js 2import React from 'react'; 3import { usePromisePortal } from 'react-promiseportal'; 4 5function App() { 6 const portal = usePromisePortal(); 7 return ( 8 <button 9 onClick={async () => { 10 // onConfirm is called with {potatoes: true} 11 // So the promise is resolved with {potatoes: true} 12 const input = await portal((onConfirm, onCancel) => { 13 return ( 14 <SomeFormComponent open> 15 <button onClick={() => onConfirm({ potatoes: true })}> 16 Confirm 17 </button> 18 <button onClick={onCancel}>Cancel</button> 19 </SomeFormComponent> 20 ); 21 }); 22 23 if (input) fetch(); 24 else alert('You cancelled.'); 25 }} 26 > 27 Click me to open a modal 28 </button> 29 ); 30}
react-promiseportal is built and maintained by babangsund.
@blog.
@github.
@twitter.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/27 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
34 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More