Last active
October 30, 2019 16:03
-
-
Save sadam1807/a024d7a56a0a4d0ebe7f369a654d3c3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react'; | |
import './App.css'; | |
import Square from './Component/Square'; | |
const App = () => { | |
const [isLoad, setLoad] = useState(false); | |
useEffect(() => { | |
let sqPaymentScript = document.createElement("script"); | |
// sandbox: https://js.squareupsandbox.com/v2/paymentform | |
// production: https://js.squareup.com/v2/paymentform | |
sqPaymentScript.src = "https://js.squareupsandbox.com/v2/paymentform"; | |
sqPaymentScript.type = "text/javascript"; | |
sqPaymentScript.async = false; | |
sqPaymentScript.onload = () => { | |
setLoad(true); | |
}; | |
document.getElementsByTagName("head")[0].appendChild(sqPaymentScript); | |
}); | |
const squarePayment = isLoad ? ( | |
<Square paymentForm={ window.SqPaymentForm }/> | |
) : ( | |
null | |
) | |
return ( | |
<div className="App"> | |
<h1>Square</h1> | |
{squarePayment} | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment