Skip to content

Plaid Link returns noop for open function #268

Description

@Namanp

I've encountered a bug with the usePlaidLink hook where the open method returned is a noop. Digging into the source code, I believe the issue is here: https://github.com/plaid/react-plaid-link/blob/master/src/usePlaidLink.ts#L51 (window.Plaid is undefined). It seems to happen more often when there are multiple components using the usePlaidLink hook (multiple microdeposits that user need to enter deposits for).

I think this is the case because Error loading Plaid: null appears in the console so there is no error but it still goes down that branch.

My hacky solution right now that works:
I use a custom hook to re-render the component on some interval if window.Plaid is undefined. I then make the useEffect hook inside of usePlaidLink retrigger by passing in a different value for products parameter. Here's a snippet:

function PlaidButton({ plaidToken }) {
  const onSuccess = async () => {}; 
  const onExit = async () => {}; // took out actual logic in onSuccess and onExit

  useRetryUntilResolved(() => typeof window.Plaid !== 'undefined'); // custom hook to retry

  const { open } = usePlaidLink({
    token: plaidToken,
    onSuccess,
    onExit,
    product: window.Plaid ? ['auth', 'transactions'] : ['auth'],
  });

  return <Button title='Verify Microdeposit Amounts' onClick={open as EventFunctionT} />;
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions