Feature usage
The useMantle()
hook provides customer
and limitForFeature
properties that contain information about how much of a given limit
feature has been used for the current Customer.
export default function () {
const { customer, limitForFeature } = useMantle();
const featureLimit = limitForFeature({featureKey: 'your_feature_key'});
const used = customer.usage['Your feature'].currentValue;
const remainingForFeature = featureLimit - used;
return (
<Page>
You have used {used} of {featureLimit}. You have {remainingForFeature} left.
</Page>
);
}
This can be helpful for giving users information or warnings when they are approaching their plan feature limits.
The customer.usage
object has the following properties:
{
// the value of the usage metric from the start of the month until now
monthToDateValue,
// the value of the usage metric from the start of the current billing period until now
currentBillingPeriodValue,
// if currentPeriod is "billing_period", equal to currentBillingPeriodValue
// if currentPeriod is "month_to_date", equal to monthToDateValue
currentValue,
// if currentPeriod is "billing_period", equal to the start date of the current billing period
// if currentPeriod is "month_to_date", equal to the start date of the current month
currentPeriodStartDate,
// if currentPeriod is "billing_period", equal to the end date of the current billing period
// if currentPeriod is "month_to_date", equal to the current date
currentPeriodEndDate,
}
Check out the @heymantle/react library to learn more.