Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usePlaidLink.open(token=null) fails silently #361

Open
Sam-Kruglov opened this issue Nov 19, 2024 · 2 comments
Open

usePlaidLink.open(token=null) fails silently #361

Sam-Kruglov opened this issue Nov 19, 2024 · 2 comments

Comments

@Sam-Kruglov
Copy link

const [linkResult, setLinkResult] = useState<{
    loading: boolean
    errorMessage?: string | null
    errorType?: string | null
  }>({ loading: true })
const { open, ready, error } = usePlaidLink({token: undefined, ...})
if (ready) open()
if (error) return <Err500/> // always null
if (linkResult.loading) return <Spinner/> // showing this forever
@phoenixy1
Copy link
Contributor

@Sam-Kruglov Thank you for reporting -- this PR leads me to believe that this behavior may be by design: #197 -- can you take a look and see if that addresses your issue?

@Sam-Kruglov
Copy link
Author

Sam-Kruglov commented Dec 5, 2024

I see, the problem is on my side because I didn't handle the !ready case. I ended up moving all that stuff into a custom hook:

function useAccountImportViaPlaidLinkWidget({ token }: Readonly<{ token: string | null }>): [
  {
    opening: boolean
    isOpen: boolean
    ready: boolean
    open: () => void
    error: MyError | null
  }, // plaid stuff
  {
    importing: boolean
    error: ApolloError | null
  } // my stuff running in onSuccess and setting some states
] {...}

Perhaps we can turn this issue into improvement suggestions:

  1. Provide opening, isOpen
  2. I'm not sure if that's the current behavior already but I think the error flow is confusing, I parsed all 3 cases into the same format and returned it into the same variable like a ?: b|c (only b or c happens at once I think, so I have one useState for those)
    a. error returned from usePlaidLink
    b. onEvent where eventName === PlaidLinkStableEvent.ERROR
    c. onExit where err != null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants