-
Notifications
You must be signed in to change notification settings - Fork 155
/
simple.tsx
38 lines (31 loc) · 1.01 KB
/
simple.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React, { useCallback, useState } from 'react';
import { usePlaidLink, PlaidLinkOnSuccess } from 'react-plaid-link';
const SimplePlaidLink = () => {
const [token, setToken] = useState<string | null>(null);
// get link_token from your server when component mounts
React.useEffect(() => {
const createLinkToken = async () => {
const response = await fetch('/api/create_link_token', { method: 'POST' });
const { link_token } = await response.json();
setToken(link_token);
};
createLinkToken();
}, []);
const onSuccess = useCallback<PlaidLinkOnSuccess>((publicToken, metadata) => {
// send public_token to your server
// https://plaid.com/docs/api/tokens/#token-exchange-flow
console.log(publicToken, metadata);
}, []);
const { open, ready } = usePlaidLink({
token,
onSuccess,
// onEvent
// onExit
});
return (
<button onClick={() => open()} disabled={!ready}>
Connect a bank account
</button>
);
};
export default SimplePlaidLink;