@terminal-api/link-react
TypeScript icon, indicating that this package has built-in type declarations

0.3.2 • Public • Published

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 exchangeToken = async ({ publicToken }) => {
  // Send the public token to your backend to exchange for a connection token
  // and store it in your database.
  return await authenticatedAxios.post('/api/terminal', { publicToken });
};

const MyComponent = () => {
  const terminal = useTerminalLink({
    // production or sandbox publishable key from the Terminal dashboard
    publishableKey: process.env.REACT_APP_TERMINAL_PUBLISHABLE_KEY,
    onSuccess: exchangeToken
  });

  return (
    <button onClick={() => terminal.open()} disabled={terminal.isOpen}>
      Setup Telematics Integration
    </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.

Readme

Keywords

none

Package Sidebar

Install

npm i @terminal-api/link-react

Weekly Downloads

158

Version

0.3.2

License

MIT

Unpacked Size

4.84 kB

Total Files

5

Last publish

Collaborators

  • jason-rai-terminal
  • cgiles95
  • terminal-root