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

Attempt to fix #285 #351

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/usePlaidLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ const noop = () => {};
*/
export const usePlaidLink = (options: PlaidLinkOptions) => {
// Asynchronously load the plaid/link/stable url into the DOM
const [loading, error] = useScript({
const [scriptLoading, error] = useScript({
src: PLAID_LINK_STABLE_URL,
checkForExisting: true,
});

// Sometimes, useScript can get into a bad state
// Specifically, if 1) loading starts 2) useScript is unmounted 3) loading finishes,
// the internal state management of react-script-hook can get into a bad state
// (see https://github.com/hupe1980/react-script-hook/issues/35)
// The other library for scripts + hooks (https://github.com/juliencrn/usehooks-ts/tree/master/packages/usehooks-ts/src/useScript)
// has a similar issue that is resolved by removing the script tag upon unmounting,
// which we don't want.
// So, we also check if `window.Plaid` exists, which is a proxy for whether Plaid's script has actually loaded
const loading = scriptLoading && !window.Plaid;

// internal state
const [plaid, setPlaid] = useState<PlaidFactory | null>(null);
const [iframeLoaded, setIframeLoaded] = useState(false);
Expand Down