()
| 1 | import React from 'react' |
| 2 | |
| 3 | export function useSkipper() { |
| 4 | const shouldSkipRef = React.useRef<boolean | null>(true) |
| 5 | const shouldSkip = shouldSkipRef.current |
| 6 | |
| 7 | // Wrap a function with this to skip a pagination reset temporarily |
| 8 | const skip = React.useCallback(() => { |
| 9 | shouldSkipRef.current = false |
| 10 | }, []) |
| 11 | |
| 12 | React.useEffect(() => { |
| 13 | shouldSkipRef.current = true |
| 14 | }) |
| 15 | |
| 16 | const result = React.useMemo( |
| 17 | () => [Boolean(shouldSkip), skip] as const, |
| 18 | [shouldSkip, skip], |
| 19 | ) |
| 20 | |
| 21 | return result |
| 22 | } |