I am creating a web app that incorporates a third party (NMI) to collect payment information. The script that NMI provides does all the work all that has to be done is add a html button with an id of 'payButton' and when that button is clicked a popup is presented to collect CC info.
Below is the only situation that I am able to get it to work.
<html lang="en">
<head>
<!-- Other imports -->
<!--
NMI Collect.js script
-->
<script src="https://secure.networkmerchants.com/token/Collect.js" data-tokenization-key="security_key"></script>
<title>React App</title>
</head>
<body></body>
</html>
class App extends Component {
render() {
return (
<div>
<button type="button" id="payButton">Pay $5</button>
</div>
)
}
}
Now the code above works just fine. I can click the button and the popup opens like it should but when I want to hide or show the button based on state of the component the popup fails to work. The code below is this situation not working.
class App extends Component {
render() {
const test = false
let data
if(test) {
data = <div></div>
} else {
data = <button type="button" id="payButton">Pay $5</button>
}
return (
<div>
{data}
</div>
)
}
}