Skip to content

Commit

Permalink
fix(website): add guard to prevent multiple initializations
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Oct 26, 2024
1 parent 7357805 commit de39b08
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions apps/website/app/routes/me.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,25 @@ export default function Index() {
const [paddle, setPaddle] = useState<Paddle>();

useEffect(() => {
initializePaddle({
token: loaderData.clientToken,
environment: loaderData.isSandbox ? "sandbox" : undefined,
}).then((paddleInstance) => {
if (paddleInstance) {
paddleInstance.Update({
eventCallback: (data) => {
if (data.name === CheckoutEventNames.CHECKOUT_COMPLETED) {
paddleInstance.Checkout.close();
toast.success(
"Purchase successful. Your order will be shipped shortly.",
);
}
},
});
setPaddle(paddleInstance);
}
});
if (!paddle)
initializePaddle({
token: loaderData.clientToken,
environment: loaderData.isSandbox ? "sandbox" : undefined,
}).then((paddleInstance) => {
if (paddleInstance) {
paddleInstance.Update({
eventCallback: (data) => {
if (data.name === CheckoutEventNames.CHECKOUT_COMPLETED) {
paddleInstance.Checkout.close();
toast.success(
"Purchase successful. Your order will be shipped shortly.",
);
}
},
});
setPaddle(paddleInstance);
}
});
}, []);

return (
Expand Down

0 comments on commit de39b08

Please sign in to comment.