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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@terminal-api/link-react

v0.4.1

Published

Welcome to the Terminal Link React SDK! This package provides a React hook, `useTerminalLink`, that allows you to seamlessly integrate and interact with [Terminal's](https://www.withterminal.com/) link component in your React application.

Downloads

1,538

Readme

Terminal Link React SDK

Welcome to the Terminal Link React SDK! This package provides a React hook, useTerminalLink, that allows you to seamlessly integrate and interact with Terminal's link component in your React application.

Getting Started

Installation

To install the Terminal Link React SDK, run the following command in your project directory:

npm install @terminal-api/link-react

Prerequisites

This package is built using React hooks, so you need to have React version 16.8.0 or later in your project.

How to Use

Here's a simple example of how to use the useTerminalLink hook in your React component:

import React from 'react';
import { useTerminalLink } from '@terminal-api/link-react';

const MyComponent = () => {
  const api = useYourBackendApi();

  // if you are defining the function inside the component
  // make sure to wrap it in useCallback
  const exchangeToken = useCallback(
    async ({ publicToken }: { publicToken: string }) => {
      // Send the public token to your backend to exchange for a connection token
      // and store it in your database.
      return await api.post('/api/terminal', { publicToken });
    },
    [api]
  );

  const terminal = useTerminalLink({
    // production or sandbox publishable key from the Terminal dashboard
    publishableKey: process.env.REACT_APP_TERMINAL_PUBLISHABLE_KEY,
    onSuccess: exchangeToken,
    params: {
      // optional parameters to pass to the link
      // see https://docs.withterminal.com/link-component for more details
      externalId: '1234'
    }
  });

  return (
    <>
      <button onClick={() => terminal.open()} disabled={terminal.isOpen}>
        Setup Telematics Integration
      </button>
      <button onClick={() => terminal.close()} disabled={!terminal.isOpen}>
        Close Terminal Link
      </button>
      <button
        onClick={() => terminal.open({ params: { provider: 'geotab' } })}
        disabled={terminal.isOpen}
      >
        Setup Geotab Integration
      </button>
      <button
        onClick={() => terminal.open({ params: { externalId: '1234' } })}
        disabled={terminal.isOpen}
      >
        Setup Integration with Custom Parameters
      </button>
    </>
  );
};

export default MyComponent;

In this example, useTerminalLink is used to create a terminal object. This object is then used to open the Terminal link when the button is clicked.

Documentation

Can reference the Terminal Link documentation section for more details on how to use the SDK.

Callbacks

To prevent infinite re-renders, wrap onSuccess and other callbacks passed to useTerminalLink with useCallback like we do above. Alternatively, if your function doesn't need any additional parameters you can define the function outside of the component to avoid the need for useCallback. This is mandatory to ensure the callback function's identity remains stable.