import * as react_jsx_runtime from 'react/jsx-runtime'; import { ReactNode, ReactElement, RefObject, ComponentType, DependencyList } from 'react'; type KeepAliveChildren = ReactNode | ReactElement | null | undefined; interface KeepAliveProps { activeCacheKey: string; children?: KeepAliveChildren; /** * max cache count default 10 */ max?: number; exclude?: Array | string | RegExp; include?: Array | string | RegExp; onBeforeActive?: (activeCacheKey: string) => void; customContainerRef?: RefObject | undefined; cacheNodeClassName?: string; containerClassName?: string; errorElement?: ComponentType<{ children: ReactNode; }>; /** * transition default false */ transition?: boolean; /** * view transition default false * * use viewTransition to animate the component when switching tabs * * @see https://developer.chrome.com/docs/web-platform/view-transitions/ */ viewTransition?: boolean; /** * transition duration default 200 */ duration?: number; aliveRef?: RefObject; /** * max alive time for cache node (second) * @default 0 (no limit) */ maxAliveTime?: number | MaxAliveConfig[]; /** * enable Activity component from react 19+ * @default false * Activity component can improve performance, but it will affect the transition effect * Attention: if enable Activity component, useEffect will trigger when the component is active */ enableActivity?: boolean; } interface MaxAliveConfig { match: string | RegExp; expire: number; } interface CacheNode { cacheKey: string; ele?: KeepAliveChildren; lastActiveTime: number; renderCount: number; } interface KeepAliveAPI { /** * Refreshes the component. * @param {string} [cacheKey] - The cache key of the component. If not provided, the current cached component will be refreshed. */ refresh: (cacheKey?: string) => void; /** * destroy the component * @param {string} [cacheKey] - the cache key of the component, if not provided, current active cached component will be destroyed */ destroy: (cacheKey?: string | string[]) => Promise; /** * destroy all components */ destroyAll: () => Promise; /** * destroy other components except the provided cacheKey * @param {string} [cacheKey] - The cache key of the component. If not provided, destroy all components except the current active cached component. */ destroyOther: (cacheKey?: string) => Promise; /** * get the cache nodes */ getCacheNodes: () => Array; } interface KeepAliveRef extends KeepAliveAPI { } declare function useKeepAliveRef(): RefObject; declare function KeepAlive(props: KeepAliveProps): react_jsx_runtime.JSX.Element; declare const useEffectOnActive: (cb: () => any, deps: DependencyList, skipMount?: boolean) => void; interface KeepAliveContext extends KeepAliveAPI { /** * whether the component is active */ active: boolean; /** * the cache key of the component */ _cacheKey: string; } declare const useKeepAliveContext: () => KeepAliveContext; declare const useLayoutEffectOnActive: (cb: () => any, deps: DependencyList, skipMount?: boolean) => void; declare const useEffectOnCreate: (cb: () => any) => void; declare const useLayoutEffectOnCreate: (cb: () => any) => void; /** * @deprecated since version 3.0.2. Use `useKeepAliveRef` instead. */ declare const useKeepaliveRef: typeof useKeepAliveRef; export { KeepAlive, type KeepAliveProps, type KeepAliveRef, useEffectOnActive, useEffectOnCreate, useKeepAliveContext, useKeepAliveRef, useKeepaliveRef, useLayoutEffectOnActive, useLayoutEffectOnCreate };