Skip to content

Instantly share code, notes, and snippets.

import { QueryBuilder } from 'knex';
import zip from './zip';
export interface Page {
items: any[];
hasNext: boolean;
hasPrevious: boolean;
}
@cmmartti
cmmartti / usePending.ts
Created February 9, 2023 02:18
usePending hook for React
import React from "react";
/**
* Hide loading states from the user unless they exceed a minimum of `wait` ms, and
* once shown, display them for a minimum of `minLength` ms.
*/
export function usePending(loading: boolean, wait = 0, minLength: number = 0) {
let [, forceRender] = React.useState<any>();
// The buffered loading value