React
Examples of common tiun SDK patterns in React. Each section is standalone — use what applies to your integration.
Initialize
Initialize the SDK inside a top-level useEffect with an empty dependency array. Return tiun.destroy() as the cleanup so dev-mode StrictMode (which double-invokes effects) tears down cleanly.
import { tiun } from '@tiun/sdk';
import { useEffect } from 'react';
function App() {
useEffect(() => {
tiun.init({
snippetId: 'YOUR_SNIPPET_ID',
language: 'en', // 'en' | 'de' | 'fr'
});
return () => tiun.destroy();
}, []);
return <>{/* your app */}</>;
}See Lifecycle and destroy() for when teardown is and isn't needed in other hosts.
Checkout
Trigger checkout on a button click. Pass the product ID from your dashboard.
Listen for user changes
Track authentication and access state with userChange. Store it in React state so your components re-render when the user changes.
Gate content
Show or hide content based on productAccess.
Login and logout
Add authentication buttons to your navigation.
Paywall events (time-based)
For time-based billing, use paywallShow and paywallHide to control access.
Content management (time-based)
Call setContent() on route changes to keep billing accurate.
Last updated
Was this helpful?

