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 useEffect and clean up with destroy() on unmount.

import { tiun } from '@tiun/sdk';
import { useEffect } from 'react';

function App() {
  useEffect(() => {
    tiun.init({
      snippetId: 'YOUR_SNIPPET_ID',
      language: 'en', // set to your site's language
    });
    return () => tiun.destroy();
  }, []);

  return <>{/* your app */}</>;
}

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?