usePurchase
SolvaPay SDK / react/src / usePurchase
Function: usePurchase()
usePurchase():
PurchaseStatus&object
Defined in: packages/react/src/hooks/usePurchase.ts:45
Hook to get current purchase status and information.
Returns the current user's purchase status, including active purchases, plan details, and payment information. Automatically syncs with the SolvaPay backend and handles loading and error states.
Returns
PurchaseStatus & object
Purchase data and status
Example
import { usePurchase } from '@solvapay/react';
function Dashboard() {
const { purchases, hasPaidPurchase, isLoading, refetch } = usePurchase();
if (isLoading) return <Spinner />;
if (!hasPaidPurchase) {
return <UpgradePrompt />;
}
return (
<div>
<h2>Welcome, Premium User!</h2>
<p>Active purchases: {purchases.length}</p>
<button onClick={() => refetch()}>Refresh</button>
</div>
);
}
See
- SolvaPayProvider for required context provider
- usePurchaseStatus for detailed status information
Since
1.0.0