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 React, { useContext, useMemo } from "react"; | |
import type { UseQueryResult } from "react-query"; | |
type ReactQueryFetchStatus = "idle" | "loading" | "error" | "success"; | |
export type UseQueryPackedUnion = "status" | "data"; | |
/* | |
type ReactQueryFetchHook<F extends Array<unknown>, Q = any, P = any> = (...hookArguments: [...F, P?]) => UseQueryResult<Q> | Pick<UseQueryResult<Q>, UseQueryPackedUnion> |
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 Yup from "yup"; | |
import type { InferType } from "yup"; | |
const UserSchema = Yup.object({ | |
name: Yup.string().required(), | |
email: Yup.string().email().required(), | |
fullname: Yup.string().required(), | |
title: Yup.string().required(), | |
gender: Yup.string().required().default("male"), | |
rating: Yup.number().min(1).max(10).required(), |
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 React, { useRef, useState, useEffect, useCallback, Children, isValidElement, cloneElement } from "react"; | |
import Router from "next/router"; | |
import { useIsFirstRender } from "react-busser"; | |
export type FormStepComponentProps = { | |
currentStep: string | number, | |
stepsTotal: number, | |
onStepChange: (data: Record<string, any>, disableFormSubmission?: boolean, shouldNavigate?: boolean) => Promise<boolean>, | |
onFormChange: (htmlForm: HTMLFormElement, htmlFormValue: { [key: string]: any }) => number; |
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 axios, { AxiosError, AxiosResponse, AxiosRequestConfig, AxiosHeaders } from "axios"; | |
import { API, authRefreshTokenStorageKeyName, authTokenStorageKeyName, userVerifyTokenStorageKeyName } from "@/constants"; | |
import { handleLogout, isCORSViolation } from "./utils"; | |
export type { AxiosError }; | |
export interface OptionsArgs<BodyType, ParamType = any> { | |
body?: BodyType; | |
headers?: { [key: string]: any }; | |
params?: ParamType, |
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 { useQueryClient } from "@tanstack/react-query"; | |
export function useReactQueryCache<D, E>(queryKey: unknown[] = []) { | |
const queryClient = useQueryClient(); | |
const queryCache = queryClient.getQueryCache(); | |
return queryCache.find<D, E>(queryKey); | |
}; |
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 { useRouter } from "next/router"; | |
import { useRef } from "react"; | |
export const useNexJSPreviousRoute = () => { | |
const router = useRouter(); | |
const ref = useRef<string | null>(null); | |
router.events?.on("routeChangeStart", () => { | |
ref.current = router.asPath; |
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 { useRouter } from "next/router"; | |
import { useState, useEffect } from "react"; | |
export const useNextJSUnsavedChangesLock = ({ | |
promptText = "You have unsaved changes - are you sure you wish to leave this page?", | |
useBrowserPrompt = true, | |
unsavedChangesStatus = false | |
}: { promptText: string, useBrowserPrompt?: boolean, unsavedChangesStatus?: boolean }) => { | |
const router = useRouter(); | |
router.beforePopState((state) => { |
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 { lazy } from "react"; | |
/** | |
* lazyWithRetry: | |
* | |
* @param {() => (() => JSX.Element)} componentImport | |
* @returns {() => JSX.Element} | |
* | |
* @see https://gist.github.com/raphael-leger/4d703dea6c845788ff9eb36142374bdb#file-lazywithretry-js | |
* |
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 React from "react"; | |
import { Provider as ReactReduxProvider } from "react-redux"; | |
import { IntlProvider as ReactIntlProvider } from "react-intl"; | |
import { BrowserRouter, BrowserRouterProps, MemoryRouter, MemoryRouterProps, Router, RouterProps } from "react-router-dom"; | |
import { History, LocationDescriptor, createBrowserHistory, createMemoryHistory } from "history"; | |
import { render, RenderOptions, RenderResult } from "@testing-library/react"; | |
import { renderHook, RenderHookResult, RenderHookOptions } from "@testing-library/react-hooks"; | |
type Separate<F, O> = F extends O ? F : null; | |
type Writeonly<T> = Separate<keyof T, keyof Readonly<T>>; |
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
type Literal = unknown | |
export interface ReducableObject { | |
[key:string]: Literal | ReducableObject; | |
} | |
export function throttleFilterCallbackRoutine<S, N extends () => void> ( | |
routine: (...args: [S]) => N, | |
routineArgs: [S], | |
interval = 500 |
NewerOlder