Next.js Discord

Discord Forum
\n ","dateCreated":"2023-07-04T09:28:02.000Z","answerCount":1,"author":{"@type":"Person","name":"Black carpenter ant"},"suggestedAnswer":{"@type":"Answer","text":"have you tried using the Script component?https://nextjs.org/docs/pages/building-your-application/optimizing/scriptsIn your case you will need two Script components in your case","url":"https://nextjs-forum.com/post/1125719659996524646#message-1125722180114726932","dateCreated":"2023-07-04T09:38:03.000Z","author":{"@type":"Person","name":"Ocicat"}}}}

external script embed with callbacks

Unanswered
Black carpenter ant posted this in #help-forum
Open in Discord
Avatar
Black carpenter antOP
what is best method to include a external url based script in react?
which also implements callbacks
example like
 <script src="https://gateway.card.com/static/checkout/checkout.min.js" data-error="errorCallback" data-cancel="cancelCallback"></script>
        <script type="text/javascript">
            function errorCallback(error) {
                  console.log(JSON.stringify(error));
            }
            function cancelCallback() {
                  console.log('Payment cancelled');
            }
            Checkout.configure({
              session: { 
                id: '<your_initiate_checkout_session_ID>'
                   }
            });
        </script>

1 Reply

Avatar
Ocicat
have you tried using the Script component?
https://nextjs.org/docs/pages/building-your-application/optimizing/scripts

In your case you will need two Script components in your case