Код: Выделить всё
export default function MyComponent() {
const [pendingCheckout, setPendingCheckout] = useState<
null | "checkoutA" | "checkoutB"
>(null);
const {
data: checkoutSessionA,
isLoading: checkoutSessionAIsLoading,
} = useQuery({ ... });
const {
data: checkoutSessionB,
isLoading: checkoutSessionBIsLoading,
} = useQuery({ ... });
useEffect(() => {
const checkoutAIsReady =
pendingCheckout === "checkoutA" &&
!optionACheckoutSessionIsLoading &&
optionACheckoutSession;
const checkoutBIsReady =
pendingCheckout === "checkoutB" &&
!optionBCheckoutSessionIsLoading &&
optionBCheckoutSession;
if (checkoutAIsReady) {
triggerCheckout(checkoutSessionA);
setPendingCheckout(null);
}
if (checkoutBIsReady) {
triggerCheckout(checkoutSessionB);
setPendingCheckout(null);
}
}, [
pendingCheckout,
checkoutSessionAIsLoading,
checkoutSessionA,
checkoutSessionBIsLoading,
checkoutSessionB,
]);
return (
// ...
setPendingCheckout("checkoutA")}
disabled={pendingCheckout === "checkoutA"}
>
{pendingCheckout === "checkoutA"
? "Proceed to checkout"
:
}
// ...
)
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... unction-in