This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useEffect, useRef } from 'react'; | |
import { debounce } from 'lodash'; | |
import { FormikValues } from 'formik'; | |
import { FormikConfig } from 'formik/dist/types'; | |
export function useDebouncedValidate<T extends FormikValues>({ | |
values, | |
validate, | |
debounceTime = 200, | |
}: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from this article https://medium.com/@alonmiz1234/retry-dynamic-imports-with-react-lazy-c7755a7d557a | |
export const retryImport = async (importer: () => Promise<any>) => { | |
try { | |
return await importer(); | |
} catch (error: any) { | |
// retry 5 times with 1 second delay and backoff factor of 2 (2, 4, 8, 16, 32 seconds) | |
for (let i = 0; i < 5; i++) { | |
await new Promise((resolve) => setTimeout(resolve, 1000 * 2 ** i)); | |
// this assumes that the error message that the browser exception will contain this specific text. | |
// if not, the url will not be able to parse and we'll get an error on that |