Skip to content

Instantly share code, notes, and snippets.

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,
}: {
@AlonMiz
AlonMiz / vue-lazy-load.ts
Last active February 24, 2023 13:01
Lazy load vue route
// 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