Git Product home page Git Product logo

react-plaid-link's Introduction

react-plaid-link npm version

React hook and components for integrating with Plaid Link

Compatibility

React 16.8+

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>
);

Available Link configuration options

ℹ️ 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.

usePlaidLink arguments

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

usePlaidLink return value

key type
open () => void
ready boolean
error ErrorEvent | null
exit (options?: { force: boolean }, callback?: () => void) => void

OAuth / opening Link without a button click

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 <></>;

Using the pre-built component instead of the usePlaidLink hook

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.

react-plaid-link's People

Contributors

aeidelson avatar aesopwolf avatar anjiren avatar cgfarmer4 avatar cooperjbrandon avatar dcripplinger avatar dependabot[bot] avatar dianeliu21 avatar edwinychu avatar furcic avatar gilakos avatar hlibco avatar jclem avatar jlaramie avatar jparadasb avatar jung35 avatar kulek1 avatar nas887 avatar otherchen avatar pbernasconi avatar piton4eg avatar rawrmaan avatar rblakejohnson avatar rcbm avatar rurabe avatar strawbee avatar subzidion avatar timruffles avatar wokkaflokka avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.