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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@truv/react

v2.4.1

Published

Truv Bridge initialization package for react

Readme

Truv React Bridge npm version

React library for integrating with the Truv Bridge and Embedded Orders

Install

npm install @truv/react

Usage

Modal

import { useState } from 'react';
import { TruvBridge } from '@truv/react';

const ModalBridge = () => {
  const [isOpened, setOpened] = useState(false);

  return (
    <>
      <button onClick={() => setOpened(true)}>Open</button>
      <TruvBridge
        bridgeToken="<bridge token>" // create it on your server via the Truv API: https://docs.truv.com/api-reference/bridge-token/users_tokens
        onClose={() => setOpened(false)}
        onSuccess={(publicToken, metaData) => {
          console.log(publicToken, metaData);
        }}
        isOpened={isOpened}
      />
    </>
  );
}

Inline

import { useState } from 'react';
import { TruvBridgeInline } from '@truv/react';

const InlineBridge = () => {
  const [isOpened, setOpened] = useState(false);

  return (
    <>
      <button onClick={() => setOpened(true)}>Open</button>
      <TruvBridgeInline
        // We can pass the properties of the div element here
        style={{ width: '300px', height: '500px', backgroundColor: 'red' }}
        // Required parameters for opening the bridge
        isOpened={isOpened}
        bridgeParams={{
          bridgeToken: "<bridge token>", // create it on your server via the Truv API: https://docs.truv.com/api-reference/bridge-token/users_tokens
          onClose: () => setOpened(false),
          onSuccess: () => {
            console.log('Success');
          }
        }}
      />
    </>
  );
}

Deferred loading and a specific version

@truv/react starts loading the latest version of the Bridge script as soon as it is imported. Import from @truv/react/lazy instead to decide when the script is loaded and to pin its version. The components are the same:

import { useState } from 'react';
import { TruvBridge, load } from '@truv/react/lazy';

// The latest version
load();
// or a specific version, loaded from https://cdn.truv.com/bridge/vX.X.X/bridge.js
load({ source: 'cdn', version: 'vX.X.X' });
// or a specific version checked with integrity (generate the hash yourself or see below)
load({ source: 'cdn', version: 'vX.X.X', integrity: 'sha384-<hash of the script>' });
// or the script you included on the page yourself, see "Bridge script included on the page" below
load({ source: 'window' });

const ModalBridge = () => {
  const [isOpened, setOpened] = useState(false);

  return (
    <>
      <button onClick={() => setOpened(true)}>Open</button>
      <TruvBridge
        bridgeToken="<bridge token>"
        onClose={() => setOpened(false)}
        onSuccess={(publicToken, metaData) => {
          console.log(publicToken, metaData);
        }}
        isOpened={isOpened}
      />
    </>
  );
}

How it works:

  • load() must be called: until then the components wait for it, and the widget never opens.
  • load() can be called any number of times, only the first call is used.
  • load() can also be called after the components are rendered, but the earlier the script starts loading, the sooner the widget opens. Call it as early as possible, e.g. on app start.

Warning: use either @truv/react or @truv/react/lazy in an app, not both: @truv/react calls load() on import, so the options passed to load() are ignored. Also don't use @truv/bridge in the same app: the script would be loaded twice.

The latest version and its Subresource Integrity hash are listed in latest.json. Details of a specific version, including its hash, are in https://cdn.truv.com/bridge/vX.X.X/manifest.json. Copy the version and the hash into your code rather than fetching these files at runtime, so the hash does not come from the same CDN as the script.

For a complete guide to pinning the Bridge version, see the Truv documentation.

Bridge script included on the page

If you include the Bridge script on the page yourself, pass source: 'window' to load() to use window.TruvBridge instead of loading the script again:

<!-- crossorigin is required for integrity -->
<script
  src="https://cdn.truv.com/bridge/vX.X.X/bridge.js"
  integrity="sha384-<hash of the script>"
  crossorigin="anonymous"
></script>
import { TruvBridge, load } from '@truv/react/lazy';

load({ source: 'window' });

const ModalBridge = () => (
  <TruvBridge
    // ...
  />
);
  • The script is never loaded from the CDN in this mode. If window.TruvBridge is not defined, the widget doesn't open and an error is thrown.
  • The Bridge script must run before the components open the widget: put its <script> tag without async before the script of your app.