react-stripe-script-loader
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "react-stripe-script-loader", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "React component that lets load Stripe script and shows React Stripe Elements", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
import React, { useState, useEffect } from 'react' | ||
import loadScript from './loadScript' | ||
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 StripeScriptLoader = ({ | ||
@@ -24,0 +5,0 @@ children, |
335859
7
136