Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-plaid-link

plaid1.6mMIT4.0.1TypeScript support: included

A React component for Plaid Link

react, react-component, plaid

readme

react-plaid-link npm version

React hook and components for integrating with Plaid Link

Compatibility

React 16.8-19.x.x

Install

With npm:

npm install --save react-plaid-link

With yarn

yarn add react-plaid-link

Documentation

Please refer to the official Plaid Link docs for a more holistic understanding of Plaid Link.

Examples

Head to the react-plaid-link storybook to try out a live demo.

See the examples folder for various complete source code examples.

Using React hooks

This is the preferred approach for integrating with Plaid Link in React.

Note: token can be null initially and then set once you fetch or generate a link_token asynchronously.

ℹ️ See a full source code examples of using hooks:

import { usePlaidLink } from 'react-plaid-link';

// ...

const { open, ready } = usePlaidLink({
  token: '<GENERATED_LINK_TOKEN>',
  onSuccess: (public_token, metadata) => {
    // send public_token to server
  },
});

return (
  <button onClick={() => open()} disabled={!ready}>
    Connect a bank account
  </button>
);

ℹ️ See src/types/index.ts for exported types.

Please refer to the official Plaid Link docs for a more holistic understanding of the various Link options and the link_token.

key type
token string | null
onSuccess (public_token: string, metadata: PlaidLinkOnSuccessMetadata) => void
onExit (error: null | PlaidLinkError, metadata: PlaidLinkOnExitMetadata) => void
onEvent (eventName: PlaidLinkStableEvent | string, metadata: PlaidLinkOnEventMetadata) => void
onLoad () => void
receivedRedirectUri string | null | undefined
key type
open () => void
ready boolean
submit (data: PlaidHandlerSubmissionData) => void
error ErrorEvent | null
exit (options?: { force: boolean }, callback?: () => void) => void

Handling OAuth redirects requires opening Link without any user input (such as clicking a button). This can also be useful if you simply want Link to open immediately when your page or component renders.

ℹ️ See full source code example at examples/oauth.tsx

import { usePlaidLink } from 'react-plaid-link';

// ...

const { open, ready } = usePlaidLink(config);

// open Link immediately when ready
React.useEffect(() => {
  if (ready) {
    open();
  }
}, [ready, open]);

return <></>;

If you cannot use React hooks for legacy reasons such as incompatibility with class components, you can use the PlaidLink component.

ℹ️ See full source code example at examples/component.tsx

import { PlaidLink } from "react-plaid-link";

const App extends React.Component {
  // ...
  render() {
    return (
      <PlaidLink
        token={this.state.token}
        onSuccess={this.onSuccess}
        // onEvent={...}
        // onExit={...}
      >
        Link your bank account
      </PlaidLink>
    );
  }
}

Typescript support

TypeScript definitions for react-plaid-link are built into the npm package. If you have previously installed @types/react-plaid-link before this package had types, please uninstall it in favor of built-in types.

changelog

Changelog

4.0.1

  • Fixed bug/regression when unmounting while Link script is loading

4.0.0 (do not use)

  • Update peer dependencies to allow React 19
  • Remove react-script-hook dependency, it is now forked into this package
  • Remove Web3-related code

3.6.1

  • Update react-script-hook version to make peer dependencies work better for React 18

3.6.0

  • Fixed an issue that can occur when unmounting the usePlaidLink hook before the underlying script tag is loaded

3.5.2

  • Fix rerender issue with PlaidEmbeddedLink
  • Add support for handler.submit

3.5.1

  • Fix build issue from version 3.5.0

3.5.0 (do not use)

Do not use version 3.5.0 because this version contains a build issue.

  • Add support for Plaid embedded Link, an experimental feature #320

3.4.1

  • Add missing events to PlaidLinkStableEvent #310
  • Update function return types for usePlaidLink #312
  • Update early return condition in usePlaidLink for possible inputs #316

3.4.0

3.3.2

  • Add transfer_status to PlaidLinkOnSuccessMetadata type #252
  • Allow React 18 in peerDependencies #256

3.3.1

  • Fix usePlaidLink hook for legacy publicKey config #247
  • Bump react-script-hook dependency to 1.6.0 to fix script loading bug #246

3.3.0

Allow token to be null in usePlaidLink config #197

3.2.2

  • Bump react-script-hook to 1.5.0 to fix 'error loading plaid' msg (#217)

3.2.1

  • (Internal) Fix invalid registry URLs in yarn.lock

3.2.0

  • Improve TypeScript types (may cause minor TS errors)

3.1.1

  • Allow React 17 in peerDependencies (#171)

3.1.0

  • Ensure Link is destroyed correctly (#146)
  • Export PlaidLinkOptions typescript types (#134)
  • (Internal) Bump node-fetch from 2.6.0 to 2.6.1 (#136)
  • (Internal) Bump elliptic from 6.5.2 to 6.5.3 (#127)
  • (Internal) Bump lodash from 4.17.15 to 4.17.19 (#124)
  • Fix a bug with the usePlaidLink ready state (#163)

3.0.0

  • Add Link token options to initialization and move onEvent types to their own interface. (#116)

2.2.3

  • (Internal) Bump websocket-extensions from 0.1.3 to 0.1.4 (#114)

2.2.2

  • Ensure Plaid link-initialize.js is embedded only once (#109)
  • Config product prop updates should refresh instance on change (#104)

2.2.1

  • (Internal) Bump yarn.lock dependencies for react-script-hook version bump (#99)

2.2.0

  • Pull in version 1.0.17 of react-script-hook (#97)

2.1.0

  • Allows public_key to be optional if a token is provided (#95)
  • Fix token initialization (#95)
  • Use the new link handler .destroy() method instead of custom internal method (#95)

2.0.3

  • Add accountSubtypes prop to configuration options (#91)

2.0.2

  • Fix publicKey prop and auto-generate PropTypes for React component (#87)

2.0.1

  • Add className prop to PlaidLink React component (#83)
  • Add type=button to PlaidLink React component (#83)

2.0.0

New

  • Add usePlaidLink hook for simpler and more configurable use-cases
  • Add Typescript support
  • Add Storybook support
  • Improve and simplify examples (located at ./examples)
  • Simplify PlaidLink HOC internals and import

Breaking changes

  • Remove support for React versions below <16.8.x
  • For the PlaidLink button component, we've removed the default import:
Before:
import PlaidLink from 'react-plaid-link';
After
import { PlaidLink } from 'react-plaid-link';