@hypothesis/frontend-shared
Version:
Shared components, styles and utilities for Hypothesis projects
23 lines (22 loc) • 660 B
TypeScript
import type { Ref, RefObject } from 'preact';
/**
* Return an object ref which synchronizes its value to another "target" ref.
*
* This is useful when a component needs an object ref for an element for
* internal use, but also wants to allow the caller to get a ref for the same
* element.
*
* The target ref can be either a callback or an object.
*
* @example
* function Widget({ elementRef }) {
* const ref = useSyncedRef(elementRef);
*
* useEffect(() => {
* ref.current.focus();
* }, []);
*
* return <input ref={ref}>...</input>;
* }
*/
export declare function useSyncedRef<T>(targetRef?: Ref<T>): RefObject<T>;