0.10.14 • Published 8 months ago

@flowglad/react v0.10.14

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

@flowglad/react

npm version npm bundle size

React components and hooks for integrating FlowGlad's billing and subscription management into your React applications. This package provides a complete solution for handling subscriptions, payment methods, and billing information in your React frontend.

Prerequisites

This package requires a FlowGlad server instance to communicate with. You can set up the server using the @flowglad/server package. See the server package documentation for setup instructions.

Installation

npm install @flowglad/react
# or
yarn add @flowglad/react
# or
pnpm add @flowglad/react

Quick Start

  1. Set up the FlowGladProvider in your app:
import { FlowgladProvider } from '@flowglad/react';

export default function RootLayout({ children }) {
  return (
    <FlowgladProvider
      loadBilling={true} // Set to true if you want to load billing data
      requestConfig={{
        headers: {
          // Add any custom headers here
        }
      }}
      theme={{
        mode: 'dark',
        dark: {
          background: '#1b1b1b',
          card: 'rgb(35 35 35)'
        }
      }}
    >
      {children}
    </FlowgladProvider>
  );
}
  1. Use the billing page component:
import { BillingPage } from '@flowglad/react';

export default function Billing() {
  return (
    <BillingPage 
      className="custom-class" 
      darkMode={true}
    />
  );
}

Features

  • Complete billing management UI components
  • Customizable themes with dark mode support
  • Type-safe hooks for accessing billing data
  • Integration with FlowGlad's server SDK
  • Support for subscriptions, payment methods, and invoices

API Reference

Components

FlowgladProvider

The main provider component that must wrap your application to enable FlowGlad functionality.

<FlowgladProvider
  loadBilling={boolean}
  requestConfig={{
    headers?: Record<string, string>
  }}
  theme={{
    mode?: 'light' | 'dark'
    dark?: {
      background?: string
      card?: string
      // ... other theme properties
    }
  }}
>
  {children}
</FlowgladProvider>

BillingPage

A complete billing management page component that includes:

  • Current subscription display
  • Pricing table for new subscriptions
  • Payment method management
  • Billing details
  • Invoice history
<BillingPage
  className?: string
  darkMode?: boolean
/>

Hooks

useBilling

Access billing data and functions throughout your application:

import { useBilling } from '@flowglad/react';

function MyComponent() {
  const billing = useBilling();
  
  // Access billing data
  const { customer, paymentMethods, invoices } = billing;
  
  // Create checkout session
  const handleSubscribe = () => {
    billing.createCheckoutSession({
      priceId: 'price_123',
      successUrl: window.location.href,
      cancelUrl: window.location.href,
      autoRedirect: true
    });
  };
}

Theme Customization

The FlowGladProvider accepts a theme configuration object that allows you to customize the appearance of all FlowGlad components:

<FlowgladProvider
  theme={{
    mode: 'dark',
    dark: {
      background: '#1b1b1b',
      card: 'rgb(35 35 35)',
      // Add more theme properties as needed
    }
  }}
>
  {children}
</FlowgladProvider>

Server Integration

This package is designed to work with the @flowglad/server package. Make sure you have set up the server routes in your backend application. The server package provides the necessary API endpoints that this React package communicates with.

Development

This package is built using:

  • TypeScript
  • React
  • Tailwind CSS for styling

License

MIT

0.10.14

8 months ago

0.10.13

8 months ago

0.10.12

8 months ago

0.10.11

8 months ago

0.10.10

8 months ago

0.10.9

8 months ago

0.10.8

9 months ago

0.10.7

9 months ago

0.10.6

9 months ago

0.10.5

10 months ago

0.10.4

10 months ago

0.10.3

10 months ago

0.10.2

10 months ago

0.10.1

10 months ago

0.10.0

10 months ago

0.9.1

10 months ago

0.9.0

10 months ago

0.8.13

10 months ago

0.8.12

10 months ago

0.8.11

10 months ago

0.8.10

10 months ago

0.8.9

10 months ago

0.8.8

10 months ago

0.8.7

10 months ago

0.8.6

10 months ago

0.8.5

10 months ago

0.8.4

10 months ago

0.8.3

10 months ago

0.8.2

10 months ago

0.8.1

10 months ago

0.8.0

10 months ago

0.7.0

11 months ago

0.6.0

11 months ago

0.5.0

11 months ago

0.4.22

11 months ago

0.4.21

11 months ago

0.4.20

11 months ago

0.4.19

11 months ago

0.4.18

11 months ago

0.4.17

11 months ago

0.4.16

11 months ago

0.4.15

11 months ago

0.4.14

11 months ago

0.4.13

11 months ago

0.4.12

11 months ago

0.4.11

11 months ago

0.4.10

11 months ago

0.4.9

11 months ago

0.4.8

11 months ago

0.4.7

11 months ago

0.4.6

11 months ago

0.4.5

11 months ago

0.4.4

11 months ago

0.4.3

11 months ago

0.4.2

11 months ago

0.4.1

11 months ago

0.4.0

11 months ago

0.2.4

11 months ago

0.2.3

11 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.1.0

11 months ago