@lexical/react
Version:
This package provides Lexical components and hooks for React applications.
21 lines (19 loc) • 495 B
text/typescript
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import type {Ref} from 'react';
export function mergeRefs<T>(...refs: Ref<T>[]): (value: null | T) => void {
return value => {
for (const ref of refs) {
if (typeof ref === 'function') {
ref(value);
} else if (ref != null) {
ref.current = value;
}
}
};
}