Skip to content

React 实用工具

¥React Utils

useMergeRefs()

合并引用数组,返回记忆的回调引用或 null

¥Merges an array of refs, returning a memoized callback ref or null.

import {useMergeRefs} from '@floating-ui/react';
 
function App() {
  const ref = useMergeRefs([ref1, ref2, ref3]);
  return <div ref={ref} />;
}

useId()

使用 React 18 的内置 useId()(如果可用),或者回退到早期 React 版本的性能稍差(需要双重渲染)的实现。

¥Uses React 18’s built-in useId() when available, or falls back to a slightly less performant (requiring a double render) implementation for earlier React versions.

import {useId} from '@floating-ui/react';
 
function App() {
  const id = useId();
}