Skip to main content

Subscriptions with React

Subscriptions build upon Reflow's authentication system, which makes them straightforward to integrate in a new or existing React project.


The first step is to install the React Auth Hook.

npm install @reflowhq/auth-react

This gives you access to a number of methods for authenticating users, checking the user's subscription status and initiating new subscriptions.

Subscription Example

You can see a live example below. You can browse through the example files by expanding the sidebar, or open the Sandbox in a new tab for easier browsing.

The two important files are App.jsx and Plan.jsx.

import "./styles.css";

import useAuth from "@reflowhq/auth-react";
import React, { useState, useEffect } from "react";
import Plan from "./Plan.jsx";

const config = {
projectID: "267418190",

export default function App() {
const auth = useAuth(config);

const [plans, setPlans] = useState([]);
const [activeTab, setActiveTab] = useState("month");

useEffect(() => {
.then((response) => response.json())
.then((r) => setPlans(
.catch((error) => console.error(error));
}, []);

return (
{auth.isSubscribed() ? (
<h1>Thank you for subscribing!</h1>
<button onClick={() => auth.modifySubscription()}>
Modify Subscription
<button className="danger" onClick={() => auth.signOut()}>
Sign Out
Plan Name: <b>{}</b>
<br />
Price:{" "}
{auth.subscription.price.price_formatted} /
<h4>RAW Subscription info:</h4>
<pre>{JSON.stringify(auth.subscription, null, " ")}</pre>
) : (
<div className="tabs">
className={activeTab === "month" ? "active" : ""}
onClick={() => setActiveTab("month")}
className={activeTab === "year" ? "active" : ""}
onClick={() => setActiveTab("year")}
<div className="card-container">
{ => (
<Plan key={} plan={p} activeTab={activeTab} auth={auth} />

The key moments in this file:

  1. We initialize the Reflow Auth library the same way that we do for authentication. You can obtain your project ID from the Reflow dashboard settings page.
  2. We use the Reflow API to request the plans that are configured in the project, and render them as cards with a Subscribe button for each. Each plan contains of one or more prices. We need the priceID to trigger the subscription flow.
  3. You can switch between Monthly and Yearly billing. We have two prices configured for the paid plan, and switch between them depending on the active tab.
import React from "react";

export default function Plan({ plan, activeTab, auth }) {
let chosenPrice = plan.prices[0];

for (let p of plan.prices) {
if (p.billing_period === activeTab) {
chosenPrice = p;

function subscribeToPlan() {
if (chosenPrice.price > 0) {
"Subscribing for paid plans is disabled in the demo in order to prevent accidental charges. You can try the free one instead."
} else {
paymentProvider: "stripe",

return (
<div className="card">
{, i) => (
<li key={i}>{f}</li>
{chosenPrice.price === 0
? "Free"
: chosenPrice.price_formatted + " / " + chosenPrice.billing_period}
<button onClick={subscribeToPlan}>Subscribe</button>

The key moment here is that we use the auth.createSubscription() method and pass a priceID of the plan. For the purposes of this example we've disabled subscriptions for the paid plan to prevent accidental charges.

If the user is not signed in your project, Reflow will automatically display a sign in/registration window first.


While developing and testing your app, you can enable the test mode parameter to try out payment flows without charging actual money.

Visit the test mode docs to learn more.