preact-spatial-navigation
Version:
A powerful Preact library for TV-style spatial navigation with LRUD algorithm, virtualized lists/grids, and smart TV support
15 lines (12 loc) • 330 B
text/typescript
import type { Ref } from 'preact';
export function mergeRefs<T = any>(...refs: Array<Ref<T> | undefined>): Ref<T> {
return (value: T | null) => {
refs.forEach((ref) => {
if (typeof ref === 'function') {
ref(value);
} else if (ref != null) {
(ref as any).current = value;
}
});
};
}