From 7cc7c80f813998c840718d4489cf26e021afdf71 Mon Sep 17 00:00:00 2001 From: Fachri Hawari Date: Wed, 2 Oct 2024 11:31:33 +0700 Subject: [PATCH] try to delay ready state --- src/app/(main)/payment/[token]/error.tsx | 2 +- src/lib/hooks/useMidtrans.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/(main)/payment/[token]/error.tsx b/src/app/(main)/payment/[token]/error.tsx index a221b34..1e6d743 100644 --- a/src/app/(main)/payment/[token]/error.tsx +++ b/src/app/(main)/payment/[token]/error.tsx @@ -6,5 +6,5 @@ export default function Error(props: { error: Error }) { console.log(props.error.message) console.log(props.error.stack) - return 'Ooppps' + return null } diff --git a/src/lib/hooks/useMidtrans.ts b/src/lib/hooks/useMidtrans.ts index 65d50ed..8e1d9e2 100644 --- a/src/lib/hooks/useMidtrans.ts +++ b/src/lib/hooks/useMidtrans.ts @@ -17,7 +17,11 @@ export function useMidtrans({ onSuccess, onPending, onError, onClose }: Midtrans script.src = 'https://app.sandbox.midtrans.com/snap/snap.js' script.setAttribute('data-client-key', process.env.NEXT_PUBLIC_MIDTRANS_CLIENT_KEY) - script.onload = () => setIsReady(true) + script.onload = () => { + setTimeout(() => { + setIsReady(true) + }, 500); // make sure the script evaluation finished + } document.body.appendChild(script) return () => { document.body.removeChild(script)