import * as React from 'react'; import { MutableRefObject, useEffect } from 'react'; /** * Type-safe clone element * * @param element * @param props * @param children */ declare function cloneValidElement(element: React.ReactElement | React.ReactNode, props?: Partial & React.Attributes, ...children: React.ReactNode[]): React.ReactElement | React.ReactNode; /** * Passes or assigns an arbitrary value to a ref function or object. * * @param ref * @param value */ declare function assignRef(ref: AssignableRef | null | undefined, value: any): void; /** * Passes or assigns a value to multiple refs (typically a DOM node). Useful for * dealing with components that need an explicit ref for DOM calculations but * also forwards refs assigned by an app. * * @param refs Refs to fork */ declare function useComposedRefs(...refs: (AssignableRef | null | undefined)[]): (node: any) => void; /** * React.Ref uses the readonly type `React.RefObject` instead of * `React.MutableRefObject`, We pretty much always assume ref objects are * mutable (at least when we create them), so this type is a workaround so some * of the weird mechanics of using refs with TS. */ type AssignableRef = { bivarianceHack(instance: ValueType | null): void; }["bivarianceHack"] | MutableRefObject; declare function createComponentHook, Props extends {} = {}>(useProps: (props: PolymorphicProps>) => [DOMProps: HTMLProps>]): ComponentHook>; declare function createComponentHook, Props extends {} = {}, Ctx = any>(useProps: (props: PolymorphicProps>) => [DOMProps: HTMLProps>, ContextType: Ctx]): ComponentHookWithContext, Ctx>; declare function createPolymorphicComponent, Props extends {} = {}>(render: (props: PolymorphicProps>) => React.ReactNode | null): PolymorphicComponent>; type As = React.ElementType; type AsProps> = { as?: DOMType; }; type RequiredAs> = NonNullable; type HTMLProps> = { children?: React.ReactNode; render?: (props: React.HTMLAttributes & React.RefAttributes) => React.ReactNode; [index: `data-${string}`]: unknown; } & Omit>, keyof OwnProps | "children">; type PolymorphicProps> = OwnProps & HTMLProps; type PolymorphicComponent> = { >(props: Omit & Omit>, keyof Props> & Required>): JSX.Element | null; (props: PolymorphicProps): JSX.Element | null; readonly $$typeof: symbol; displayName?: string; }; type ComponentHook> = { = RequiredAs>(props?: Omit & Omit>, keyof Props> & AsProps): [DOMProps: Omit>, "render" | "children">]; displayName?: string; }; type ComponentHookWithContext, Ctx> = { = RequiredAs>(props?: Omit & Omit>, keyof Props> & AsProps): [ DOMProps: Omit>, "render" | "children">, ContextType: Ctx ]; displayName?: string; }; type ContextProvider = React.FC>; type ChildContext = T & { contextIndex: number; parentContext: T | undefined; }; declare function createContext(rootName: string, defaultContext?: ContextValueType | null | undefined): [ ContextProvider, (childName: string) => ChildContext ]; /** * React hook for creating a value exactly once. * @see https://github.com/Andarist/use-constant */ declare function useConstant(fn: () => ValueType): ValueType; /** * Check if a component is controlled or uncontrolled and return the correct * state value and setter accordingly. If the component state is controlled by * the app, the setter is a noop. * * @param controlledValue * @param defaultValue */ declare function useControlledState({ controlledValue, defaultValue, calledFrom, }: { controlledValue: T | undefined; defaultValue: T | (() => T); calledFrom?: string; }): [T, React.Dispatch>]; /** * Converts a callback to a ref to avoid triggering re-renders when passed as a * prop and exposed as a stable function to avoid executing effects when passed * as a dependency. */ declare function useEvent any>(callback: T | null | undefined): T; /** * Adds a DOM event listener * * @param eventName * @param listener * @param element */ declare function useEventListener(eventName: K, listener: (event: WindowEventMap[K]) => any, element?: HTMLElement | Document | Window | EventTarget): void; /** * Detect when focus changes in our document. * * @param handleChange * @param when * @param ownerDocument */ declare function useFocusChange(handleChange?: (activeElement: Element | null, previousActiveElement: Element | null, event?: FocusEvent) => void, when?: "focus" | "blur", ownerDocument?: Document): void; /** * Forces a re-render, similar to `forceUpdate` in class components. */ declare function useForceUpdate(): () => void; /** * useId * * Autogenerate IDs to facilitate WAI-ARIA. * * The returned ID will initially be `null` and will update after a component * mounts. Users will need to supply their own ID if they need consistent values * for SSR. * * @see Docs https://TODO.com */ declare function useId(): string | null; declare function useId(idFromProps: string): string; declare function useId(idFromProps: number): number; declare function useId(idFromProps: string | number): string | number; declare function useId(idFromProps: string | undefined | null): string | null; declare function useId(idFromProps: number | undefined | null): number | null; declare function useId(idFromProps: string | number | undefined | null): string | number | null; /** * React currently throws a warning when using useLayoutEffect on the server. To * get around it, we can conditionally useEffect on the server (no-op) and * useLayoutEffect in the browser. We occasionally need useLayoutEffect to * ensure we don't get a render flash for certain operations, but we may also * need affected components to render on the server. One example is when setting * a component's descendants to retrieve their index values. * * Important to note that using this hook as an escape hatch will break the * eslint dependency warnings unless you rename the import to `useLayoutEffect`. * Use sparingly only when the effect won't effect the rendered HTML to avoid * any server/client mismatch. * * If a useLayoutEffect is needed and the result would create a mismatch, it's * likely that the component in question shouldn't be rendered on the server at * all, so a better approach would be to lazily render those in a parent * component after client-side hydration. * * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85 * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js * * @param effect * @param deps */ declare const useIsomorphicLayoutEffect: typeof useEffect; declare function useLazyRef any>(fn: F): React.MutableRefObject>; /** * Returns the previous value of a reference after a component update. * * @param value */ declare function usePrevious(value: ValueType): ValueType | null; /** * Call an effect after a component update, skipping the initial mount. * * @param effect Effect to call * @param deps Effect dependency list */ declare function useUpdateEffect(effect: React.EffectCallback, deps?: React.DependencyList): void; export { As, AsProps, AssignableRef, ComponentHook, ComponentHookWithContext, ContextProvider, PolymorphicComponent, assignRef, cloneValidElement, createComponentHook, createContext, createPolymorphicComponent, useEvent as unstable_useEvent, useComposedRefs, useConstant, useControlledState, useEventListener, useFocusChange, useForceUpdate, useId, useIsomorphicLayoutEffect, useLazyRef, usePrevious, useUpdateEffect };