@comms-id/website-logo-react

中文文档
0.2.2发布于 2026/10/21SEE LICENSE IN LICENSETypeScriptES Module

React hook and component for the Comms.ID Website logo field: Website logo image, accessible, no layout shift, with the data attribution

此软件包已被标记为弃用

Removed. Comms.ID products are served live, nothing to install: https://cdn.comms.id/website-logo-lookup/latest.js

原始使用文档
文档目录3 节
  1. What the image does
  2. Your own markup: useWebsiteLogo
  3. The component

@comms-id/website-logo-react

A React hook and a finished component for the Comms.ID Website logo image: the logo of a website, in a box of a fixed size with a letter as the fallback. No layout shift, and the visitor's browser contacts only Comms.ID. React 18 or later; it depends on @comms-id/website-logo and nothing else.

import { createWebsiteLogoBrowserClient } from "@comms-id/website-logo/browser";
import { WebsiteLogoImage } from "@comms-id/website-logo-react";

const client = createWebsiteLogoBrowserClient({ relayUrl: "/api/comms-id/logo" });

export const Customer = () => <WebsiteLogoImage client={client} site="example.com" size={48} />;

relayUrl is your own server route, set up with @comms-id/relay: your server signs the call as your registered app, so the browser holds no credential.

What the image does

  • A site: a hostname such as example.com, or a URL. The service is asked at once; nothing is asked for an empty or invalid site.
  • The image is the Comms.ID copy named in resolution.imageUrl, loaded from api.comms.id (or api-test.comms.id). The upstream logoUrl is never loaded: the visitor's browser contacts only Comms.ID, so a visitor's address is not sent to a third party. A reply that names any other host is shown as the letter.
  • The box has its size from the first render, so the page never moves while the image loads. The first letter of the site shows in it while the image loads and when there is no image (the service has none, the call failed, or the browser could not load the image). The box is a named image (<site> logo, or your alt).
  • A failed call is never shown as "no logo": it fires comms-id-error (the letter stays).
const logo = useWebsiteLogo({ client, site });
const picture = logo.getImageProps();
return (
  <span {...logo.getBoxProps()}>
    {logo.state.monogram}
    {picture === undefined ? null : <img {...picture} />}
  </span>
);

getBoxProps makes the box a named image. getImageProps is undefined until there is an image on a Comms.ID host, and carries referrerPolicy="no-referrer" and the error handler that brings back the letter. Style the box yourself: give it a fixed size.

The component

Props: client and site (required; site may be undefined while you do not know it), alt (default " logo"), size (pixels, 8 to 512; default 48), className, onResult, onFallback (missing, blocked or failed), onError, extraOrigins (a development host).

Style it with the custom properties --comms-id-text, --comms-id-surface, --comms-id-border, --comms-id-radius or the comms-id-website-logo__* class names. It needs no stylesheet. It renders on the server with the same box, name and letter (and no image: the image is asked for in the browser).

Your Content-Security-Policy needs img-src https://api.comms.id (and https://api-test.comms.id for the TEST service), and no other image host.

LICENSE is the consumer client licence. src/ is generated by @comms-id/forge-transformers and is never edited by hand.

版本与发布记录

@comms-id/website-logo-react 共发布 2 个版本,首次发布于 2026/10/21;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.2.2latest2026/10/2113 天前
0.0.0-stage2026/10/2113 天前

关于 @comms-id/website-logo-react 的常见问题

@comms-id/website-logo-react 是什么?

用于通信的React钩子和组件。ID网站标识字段:网站标识图像,可访问,无布局移位,具有数据属性注意:该包已被作者标记为弃用——Removed. Comms.ID products are served live, nothing to install: https://cdn.comms.id/website-logo-lookup/latest.js

如何安装 @comms-id/website-logo-react?

在项目目录运行 npm install @comms-id/website-logo-react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@comms-id/website-logo-react 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@comms-id/website-logo-react 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@comms-id/website-logo-react 可以商用吗?

@comms-id/website-logo-react 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@comms-id/website-logo-react 还在维护吗?

最新版本 0.2.2 发布于 2026/10/21(13 天前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/10/21。作者已将其标记为弃用,新项目建议寻找替代方案。