In your react-native project directory:
npm install --save react-native-plaid-link-sdk
When upgrading from a previous major version of this library, see the notes here for additional instructions.
Add Plaid
to your project’s Podfile as follows (likely located at ios/Podfile
). The latest version is .
pod 'Plaid', '~> <insert latest version>'
Then install your cocoapods dependencies:
(cd ios && pod install)
Add a Run Script build phase (after the [CP] Embed Pods Frameworks step) to your target as described in Plaid Link for iOS documentation. This strips simulator symbols from App Store release builds.
That’s it if using a recent react-native version with autolinking support.
If using a version of react-native without autolinking support, then you will need to:
react-native link react-native-plaid-link-sdk
followed by
Libraries
▶ Add Files to [your project's name]
node_modules
▶ react-native-plaid-link-sdk
▶ ios
and add RNLinksdk.xcodeproj
libRNLinksdk.a
to your project’s Build Phases
▶ Link Binary With Libraries
Cmd+R
)<com.plaid.example
android/app/src/main/java/<AppName>/MainApplication.java
import com.plaid.PlaidPackage;
to the imports sectionpackages.add(new PlaidPackage());
to List<ReactPackage> getPackages();
android/app/build.gradle
dependencies {
// ...
implementation project(':react-native-plaid-link-sdk')
implementation 'com.squareup.okhttp3:okhttp-urlconnection:<insert at least version 4.x>'
}
android/settings.gradle
include ':react-native-plaid-link-sdk'
project(':react-native-plaid-link-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-plaid-link-sdk/android')
React Native SDK | Android SDK | iOS SDK | Status |
---|---|---|---|
6.x.x | [3.0.0+) | >=2.0.1 | Active |
5.x.x | [2.1.0+) | >=1.1.34 | Active |
4.x.x | [2.0.0-2.1.0) | <=1.1.33 | Active |
3.x.x | [1.0.0-2.0.0) | <=1.1.33 | Deprecated |
2.x.x | [0.3.0-1.0.0) | <=1.1.27 | Deprecated |
1.x.x | [0.1.0-0.3.0) | <=1.1.24 | Deprecated |
To initialize Plaid Link, you will need to first create a link_token
at /link/token/create. After creating a link_token, you’ll need to pass it into your app and use it to launch Link:
import { Text } from 'react-native';
import PlaidLink from 'react-native-plaid-link-sdk';
const MyPlaidComponent = () => {
return (
<PlaidLink
// Replace any of the following <#VARIABLE#>s according to your setup,
// for details see https://plaid.com/docs/quickstart/#client-side-link-configuration
token = {"<#GENERATED_LINK_TOKEN#>"}
onSuccess={data => console.log('success: ', data)}
onExit={data => console.log('exit: ', data)}
>
<Text>Add Account</Text>
</PlaidLink>
);
};
For Link Token based OAuth support, you must configure your link_token
with a redirect_uri
to support OAuth on iOS. Other than setting the redirect_uri
, which must be a universal link, when you create the link_token
no further configuration is required. Notably, no props are required on the React Native side.
For non-Link Token based OAuth support, you must pass two props to the PlaidLink React Native component:
oauthRedirectUri
this is the same uri you would pass to the redirect_uri
for Link Token based OAuth. It must be registered as a universal link.oauthNonce
this is a 16 character nonce.In order for the React Native app to respond to the universal link, you will need to update your AppDelegate to inform the React Native Linking library when the universal link is received. See OAuth requirements for more information.
The React Native Plaid module emits onEvent
events throughout the account linking process — see details here. To receive these events in your React Native app, wrap the PlaidLink
react component with the following in order to listen for those events:
import React from 'react';
import { Text, NativeEventEmitter, NativeModules, Platform } from 'react-native';
class PlaidEventContainer extends React.Component {
componentDidMount() {
const emitter = new NativeEventEmitter(Platform.OS === 'ios' ? NativeModules.RNLinksdk : NativeModules.PlaidAndroid);
this._listener = emitter.addListener('onEvent', (e) => console.log(e));
}
componentWillUnmount() {
if (this._listener) {
this._listener.remove();
}
}
render() {
return (
<PlaidLink
token={<#GENERATED_LINK_TOKEN#>}
onSuccess={data => console.log('success: ', data)}
onExit={data => console.log('exit: ', data)}
>
<Text>Add Account</Text>
</PlaidLink>
);
}
}
You can also use the usePlaidEmitter
hook in react functional components:
usePlaidEmitter((event) => {
console.log(event)
})
By default, PlaidLink
renders a TouchableOpacity
component. You may override the component used by passing component
that accepts an onPress
callback prop and componentProps
. For example:
<PlaidLink
token = {"<#GENERATED_LINK_TOKEN#>"}
component= {Button}
componentProps = {{title: 'Add Account'}}
onSuccess = {(result) => {console.log('Success: ', result)}}
onError = {(result) => {console.log('Error: ', result)}}
>
Author: plaid
Source Code: https://github.com/plaid/react-native-plaid-link-sdk
#react #react-native #mobile-apps