import React, { createContext, useContext, useMemo } from 'react' import type { ReactNode } from 'react' import type { AnyAsyncFunction, AnyFunction, AsyncBatcherOptions, AsyncDebouncerOptions, AsyncQueuerOptions, AsyncRateLimiterOptions, AsyncThrottlerOptions, BatcherOptions, DebouncerOptions, QueuerOptions, RateLimiterOptions, ThrottlerOptions, } from '@tanstack/pacer' /* eslint-disable @eslint-react/no-context-provider, @eslint-react/no-use-context -- * React <19: keep Context.Provider and useContext; `use` and `` as provider need React 19+. */ export interface PacerProviderOptions { asyncBatcher?: Partial> asyncDebouncer?: Partial> asyncQueuer?: Partial> asyncRateLimiter?: Partial> asyncThrottler?: Partial> batcher?: Partial> debouncer?: Partial> queuer?: Partial> rateLimiter?: Partial> throttler?: Partial> } interface PacerContextValue { defaultOptions: PacerProviderOptions } const PacerContext = createContext(null) export interface PacerProviderProps { children: ReactNode defaultOptions?: PacerProviderOptions } const DEFAULT_OPTIONS: PacerProviderOptions = {} export function PacerProvider({ children, defaultOptions = DEFAULT_OPTIONS, }: PacerProviderProps) { const contextValue: PacerContextValue = useMemo( () => ({ defaultOptions, }), [defaultOptions], ) return ( {children} ) } export function usePacerContext() { return useContext(PacerContext) } export function useDefaultPacerOptions() { const context = useContext(PacerContext) return context?.defaultOptions ?? {} }