Gathering detailed insights and metrics for react-async-script-hoc
Gathering detailed insights and metrics for react-async-script-hoc
npm install react-async-script-hoc
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
3,614
Last Day
1
Last Week
5
Last Month
14
Last Year
147
6 Stars
19 Commits
3 Forks
2 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
0.7.0
Package Id
react-async-script-hoc@0.7.0
Unpacked Size
135.09 kB
Size
36.87 kB
File Count
6
NPM Version
6.1.0
Node Version
8.9.4
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-37.5%
5
Compared to previous week
Last month
0%
14
Compared to previous month
Last year
-20.5%
147
Compared to previous year
Load 3rd party scripts and styles from a url in a higher order component
yarn add react-async-script-hoc
This is a simple little higher-order component (HOC) for loading scripts from a url
and giving it to you in props instead of window
.
Some 3rd party vendors don't make npm packages for their scripts & you must load them from a url.
This really sucks, but it's usually to comply with regulations (Stripe.js, ReCaptcha, etc.)
For example, with Stripe, instead of adding a script tag, you can use this & then get window.Stripe
as a prop.
For styles, this might be useful if you're using a 3rd party package that comes with CSS but you prefer CSS-in-JS.
You can also return a method (or a promisified method) instead of the whole global object.
Yay modularity & lazy loading!
##Usage
Example:
1import withAsync from 'react-async-hoc'; 2const statelessComponent = (props) => { 3 const {stripe} = props; 4 // undefined if the script hasn't loaded yet 5 if (!stripe) { 6 return <Loading/> 7 } 8 9 onEventHandler = () => { 10 stripe.stealMoney(); 11} 12 return <div onClick={onEventHandler}>I can haz?</div> 13} 14 15const stripeCb = () => { 16 const stripe = window.Stripe; 17 stripe.setPublishableKey(stripeKey); 18 return { 19 stripe, 20 // example of returning a promisified method when the API doesn't follow a node standard callback 21 createToken: (fields) => new Promise((resolve) => { 22 stripe.card.createToken(fields, (status, response) => { 23 resolve(response); 24 }) 25 }) 26 }; 27}; 28 29return withAsync({'https://js.stripe.com/v2/': stripeCb});
##API
withAsync(fetchScripts, fetchStyles)
fetchScripts
: An object containing all the scripts you want to fetch.
If you don't know this until runtime, have the parent component pass in a fetchScripts
property.
Pass in as many scripts as you want to load.
key
: the url of the script to fetchvalue
: the callback to run one that script has been loadedfetchStyles
: Identical to fetchScripts
, but for loading CSS.MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
Found 0/19 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
70 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
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