Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

665 B
Raw Blame
"use client";

import { createContext, type PropsWithChildren, use } from "react";

type StripeContext = { plans: { yearly: string; monthly: string } };
const StripeContext = createContext<StripeContext | undefined>(undefined);

export function StripeContextProvider({
	children,
	plans,
}: PropsWithChildren & Partial<StripeContext>) {
	return (
		<StripeContext.Provider value={plans ? { plans } : undefined}>
			{children}
		</StripeContext.Provider>
	);
}

export function useStripeContext() {
	const context = use(StripeContext);
	if (!context) {
		throw new Error(
			"useStripeContext must be used within a StripeContextProvider",
		);
	}
	return context;
}