@liveblocks/react-ui
Version:
A set of React pre-built components for the Liveblocks products. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.
39 lines (35 loc) • 1.01 kB
JavaScript
"use client";
import { jsxs } from 'react/jsx-runtime';
import { useUser } from '@liveblocks/react';
import { useMemo } from 'react';
import { useOverrides } from '../../overrides.js';
import { useCurrentUserId } from '../../shared.js';
import { cn } from '../../utils/cn.js';
function User({
userId,
replaceSelf,
className,
children,
...props
}) {
const currentId = useCurrentUserId();
const { user, isLoading } = useUser(userId);
const $ = useOverrides();
const resolvedUserName = useMemo(() => {
return replaceSelf && currentId === userId ? $.USER_SELF : user?.name ?? $.USER_UNKNOWN;
}, [replaceSelf, currentId, userId, $.USER_SELF, $.USER_UNKNOWN, user?.name]);
return /* @__PURE__ */ jsxs(
"span",
{
className: cn("lb-name lb-user", className),
"data-loading": isLoading ? "" : void 0,
...props,
children: [
isLoading ? null : resolvedUserName,
children
]
}
);
}
export { User };
//# sourceMappingURL=User.js.map