npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@recast-sdk/recast-react

v1.6.0

Published

The `recast-react` library provides the a SDK for RecastPay for React applications. The SDK allows for a redirect or pop-up flow to be integrated with React applications via the provided context and hooks. The SDK also provides branded components to ease

Readme

@recast-sdk/recast-react

The recast-react library provides the a SDK for RecastPay for React applications. The SDK allows for a redirect or pop-up flow to be integrated with React applications via the provided context and hooks. The SDK also provides branded components to ease integration.

Installation

Install the package

npm i @recast-sdk/recast-react

Place the RecastProvider at the base of the application:

import { RecastProvider } from '@recast-sdk/recast-react';

export const App = () => {
  return (
    // set sandbox to true for testing
    <RecastProvider sandbox={true}>
      {/* Other providers, router, etc... */}
    </RecastProvider>
  );
};

export default App;

This configures the RecastPay hooks so they can be consumed within the application.

Pop-up Flow

The RecastPay Pop-up flow is actioned by calling the useRecastPopUp hook,

Start Purchase

The useRecastPopUp hook takes two optional callbacks, onSuccess and onFailure, the hook manages the cross Window communication and security required for message passing.

The onSuccess callback can do many things, one might be to navigate to to a new page. The useRecastJWTVerify can be used to verify the returned AccessToken before further action is taken.

import {
  useRecastPopUp,
  type FailureResult,
  type SuccessResult,
} from '@recast-sdk/recast-react';

export const PurchaseItem = () => {
  // Get the intentToken from your API
  const { intentToken } = useQuery();
  const { verify } = useRecastJWTVerify();

  // do something onSuccess...
  const onSuccess = useCallback(
    (result: SuccessResult) => {
      const verifiedResult = verify(result.contentAccessToken);
      console.log(verifiedResult);
    },
    [verify]
  );

  // do something onFailure...
  const onFailure = useCallback((result: FailureResult) => {
    console.error(result);
  }, []);

  // Pass the callbacks into the useRecastPopUp
  const { purchase } = useRecastPopUp(onSuccess, onFailure);

  return (
    <div>
      <span>Item Title</span>
      {intentToken ? (
        <button type="button" onClick={() => purchase(intentToken)}>
          Purchase
        </button>
      ) : null}
    </div>
  );
};

export default PurchaseItem;

Safari-safe Popups: preparePopup

To ensure popups are not blocked by Safari or other browsers, call the preparePopup method from the useRecastPopUp hook synchronously in your button's onClick handler, before any async work (such as fetching an intent token). Then call purchase as usual when ready.

import { useRecastPopUp } from '@recast-sdk/recast-react';

export const PurchaseButton = ({ intentToken }: { intentToken: string }) => {
  const { preparePopup, purchase } = useRecastPopUp();

  const handleClick = async () => {
    preparePopup(); // Open popup synchronously
    // ...fetch or compute intentToken asynchronously
    purchase(intentToken);
  };

  return <button onClick={handleClick}>Purchase</button>;
};

Redirect Flow

The RecastPay Redirect flow is actioned by calling the useRecastRedirect hook providing a contextual purchase function. The purchase function consumes an intentToken and redirectUri, the intentToken is generated by a call to the RecastPay API and the redirectUrl is used to redirect back to the application once the RecastPay process is either complete or exited.

n.b. the useRecastRedirect hook must be used with in a RecastContext provided by a RecastProvider.

Start Purchase

The redirectUri must exist in your application and application state must be maintained by the application if required.

import { useRecastRedirect } from '@recast-sdk/recast-react';

export const PurchaseItem = () => {
  // Get the intentToken from your API
  const { intentToken } = useQuery();
  // Get the Purchase call
  const { purchase } = useRecastRedirect();

  return (
    <div>
      <span>Item Title</span>
      {intentToken ? (
        <button
          type="button"
          onClick={() => purchase(intentToken, 'redirectUri')}
        >
          Purchase
        </button>
      ) : null}
    </div>
  );
};

export default PurchaseItem;

Complete Purchase

On purchase completion RecastPay will redirect back to the redirectUri with data passed back via a query string.

import {
  useRecastAccessToken,
  useRedirectPurchaseResult,
  SuccessResult,
  FailureResult,
} from '@recast-sdk/recast-react';

export const ViewItem = () => {
  // useRecastAccessToken handles the query string, verifying the Access Token
  // and providing the success state, access token payload and errors
  const { success, accessToken, error } = useRecastAccessToken(location);

  // or using callbacks
  const onSuccess = (result: SuccessResult) => {
    /**/
  };
  const onFailure = (result: FailureResult) => {
    /**/
  };
  useRedirectPurchaseResult(location, onSuccess, onFailure);

  return (
    <div>
      <span>Item Title</span>
      {success ? <div>Item Content</div> : null}
      {error ? <div>Error!</div> : null}
    </div>
  );
};

export default ViewItem;