react-stripe-script-loader
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "react-stripe-script-loader", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "React component that lets load Stripe script and shows React Stripe Elements", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "./node_modules/.bin/babel src/index.js --out-file index.js" | ||
"build": "./node_modules/.bin/babel src --out-file index.js" | ||
}, | ||
@@ -11,0 +11,0 @@ "repository": { |
import React, { useState, useEffect } from 'react' | ||
import loadScript from './loadScript' | ||
@@ -12,2 +11,23 @@ const StripeScriptLoader = ({ | ||
useEffect(() => { | ||
const loadScript = (src, uniqueId) => | ||
new Promise((resolve, reject) => { | ||
const scriptElement = document.getElementById(uniqueId) | ||
if (!scriptElement) { | ||
const script = document.createElement('script') | ||
script.src = src | ||
script.id = uniqueId | ||
const handleLoadScriptSuccess = () => resolve({ successful: true }) | ||
const handleLoadScriptFail = event => reject({ error: event }) | ||
script.addEventListener('load', handleLoadScriptSuccess, { | ||
once: true, | ||
}) | ||
script.addEventListener('error', handleLoadScriptFail, { once: true }) | ||
document.head.appendChild(script) | ||
} else { | ||
resolve({ successful: true }) | ||
} | ||
}) | ||
const fetchData = async () => { | ||
@@ -14,0 +34,0 @@ const result = await loadScript(script, uniqueId) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
334824
6