Gathering detailed insights and metrics for @postinumero/use-async
Gathering detailed insights and metrics for @postinumero/use-async
Gathering detailed insights and metrics for @postinumero/use-async
Gathering detailed insights and metrics for @postinumero/use-async
npm install @postinumero/use-async
Typescript
Module System
Node Version
NPM Version
60.8
Supply Chain
89.6
Quality
74.4
Maintenance
100
Vulnerability
98.9
License
@postinumero/unplugin-formatjs@0.1.5
Updated on May 06, 2025
@postinumero/react-router-oidc-client@0.2.2
Updated on May 06, 2025
@postinumero/formatjs-tools@0.1.3
Updated on May 06, 2025
@postinumero/unplugin-formatjs@0.1.4
Updated on Apr 29, 2025
@postinumero/unplugin-formatjs@0.1.3
Updated on Apr 29, 2025
@postinumero/formatjs-tools@0.1.2
Updated on Apr 29, 2025
TypeScript (81.57%)
JavaScript (17.33%)
Shell (0.5%)
HTML (0.38%)
CSS (0.21%)
Total Downloads
70,783
Last Day
20
Last Week
140
Last Month
786
Last Year
13,776
3 Stars
290 Commits
1 Watchers
2 Branches
1 Contributors
Updated on May 06, 2025
Latest Version
0.3.6
Package Id
@postinumero/use-async@0.3.6
Unpacked Size
45.34 kB
Size
11.93 kB
File Count
78
NPM Version
8.19.2
Node Version
16.18.0
Cumulative downloads
Total Downloads
Last Day
25%
20
Compared to previous day
Last Week
6.1%
140
Compared to previous week
Last Month
-24.1%
786
Compared to previous month
Last Year
-50.1%
13,776
Compared to previous year
Create a suspending hook from an async function, an async generator or a function that returns an async iterator.
recall
function for re-executing the function and rerendering related components from anywhere1import { Suspense } from 'react'; 2import { create } from '@postinumero/use-async'; 3import axios from 'axios'; 4 5const [useAxios] = create(axios); 6 7function Todo({ id }) { 8 const { data } = useAxios(`https://jsonplaceholder.typicode.com/todos/${id}`); 9 10 return <pre>{JSON.stringify(data, null, 2)}</pre>; 11} 12 13function App() { 14 return ( 15 <Suspense fallback="Loading..."> 16 <Todo id="1" /> 17 </Suspense> 18 ); 19}
1import { Suspense } from 'react'; 2import { create } from '@postinumero/use-async'; 3import { Repeater } from '@repeaterjs/repeater'; 4 5const [useTimestamp] = create( 6 () => 7 new Repeater(async (push, stop) => { 8 push(Date.now()); 9 const interval = setInterval(() => push(Date.now()), 1000); 10 await stop; 11 clearInterval(interval); 12 }) 13); 14 15function Timestamp() { 16 return <div>Timestamp: {useTimestamp()}</div>; 17} 18 19function App() { 20 return ( 21 <Suspense fallback="Loading..."> 22 <Timestamp /> 23 </Suspense> 24 ); 25}
create(fn[, config])
For creating shortcut functions of the rest of the API, without needing to pass fn
and config
each time.
fn: AsyncFunction
config
: Config (optional)An array of functions [useAsync, recall, useAsyncSafe]
. Each of the returned function take just the ...args
as its arguments.
useAsync(fn[, config[, args]])
fn: AsyncFunction
config
: Config (optional)args: arguments[]
for fn
(optional)Resolved value of fn(...args)
.
A thrown exception from fn
or a promise for React Suspense.
useAsyncSafe(fn[, config[, args]])
fn: AsyncFunction
config
: Config (optional)args: arguments[]
for fn
(optional)An array [error, value]
, where error
is either null
or a thrown exception from fn(...args)
, and value
is resolved value of fn(...args)
.
Promise for React Suspense.
recall(fn[, config[, args]])
(async)If there are components currently mounted using any of the hooks and the same arguments (fn, config, args), fn(...args)
gets called. When fn
resolves, components will rerender with the new value.
fn: AsyncFunction
config
: Config (optional)args: arguments[]
for fn
(optional)Resolves with undefined
, when fn(...args)
resolves.
Prop | Example | Default value | Description |
---|---|---|---|
id | "axios" | undefined | Cache values using id as key instead of fn . Required in SSR. |
createSSRCache
to get SSRCacheProvider
and ssrData
<App>
with <SSRCacheProvider>
react-ssr-prepass
to handle suspsensessrData()
. ssrData
accepts a map
function, which is called for each data entry with 2 arguments: data
, { id, args }
.<script>
before the application1import { /* nothing, */ createSSRCache } from '@postinumero/use-async'; 2import ssrPrepass from 'react-ssr-prepass'; 3 4//... 5 6const { ssrData, SSRCacheProvider } = createSSRCache(); 7 8const element = ( 9 <SSRCacheProvider> 10 <App /> 11 </SSRCacheProvider> 12); 13await ssrPrepass(element); 14 15const app = ReactDOMServer.renderToString(element); 16 17res.send( 18 html.replace( 19 '<div id="root"></div>', 20 `<script>${ssrData(([error, response]) => 21 // error ? nothing : 22 [ 23 error, 24 response && { 25 data: response.data, 26 headers: response.headers, 27 status: response.status, 28 }, 29 ] 30 )}</script><div id="root">${app}</div>` 31 ) 32);
Import from @postinumero/use-async/loading-state
to use the { isLoading, data, error }
style API. Example:
1import { create } from '@postinumero/use-async/loading-state'; 2import axios from 'axios'; 3 4const [, , useAxiosSafe] = create(axios); 5 6function User({ id }) { 7 const { isLoading, data, error } = useAxiosSafe(`/api/users/${id}`); 8 9 if (isLoading) { 10 return 'Loading...'; 11 } 12 13 return <div>First name: {data.data.first_name}</div>; 14}
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
7 existing vulnerabilities detected
Details
Reason
Found 0/17 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-05-05
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