cometchat-react-native-sdk
The headless CometChat Chat SDK for React Native — a method → contract map for the fallback path, plus init/login ordering and listener lifecycle. Use when the UI Kit has no component for what you need, or when building a fully custom chat UI. Triggers: CometChat SDK React Native, headless chat RN, custom chat UI React Native, sendMessage React Native, CometChat listener leak, banned members RN, change my avatar, update my profile, update user details React Native, log the user out.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 1.6k
- Forks
- 491
01 前言 Front Matter
- name
- cometchat-react-native-sdk
- license
- MIT
- metadata
- { "tags": "chat cometchat react-native sdk headless methods listeners fallback", "author": "CometChat", "version": "1.0.0" }
- description
- The headless CometChat Chat SDK for React Native — a method → contract map for the fallback path, plus init/login ordering and listener lifecycle. Use when the UI Kit has no component for what you need, or when building a fully custom chat UI. Triggers: CometChat SDK React Native, headless chat RN, custom chat UI React Native, sendMessage React Native, CometChat listener leak, banned members RN, change my avatar, update my profile, update user details React Native, log the user out.
- compatibility
- React Native >=0.77; @cometchat/chat-sdk-react-native ^4.0.28
02 资源文件 2
- 参考文档references/method-map.md16.4 KB
- 参考文档references/page-map.md11.1 KB
03 SKILL.md 正文
Ground truth:
@cometchat/chat-sdk-react-native@4+ catalogrn-sdk-v4.json(317 symbols). Signatures inreferences/method-map.mdare verbatim from the installed.d.ts, not from prose. Docs:/sdk/react-native/llms-react-native-v4.md(scoped index).
Companion skills (read first)
cometchat-react-native-core— install, provider chain, init→login→render. Assumed, not repeated here.
Use this skill when
- the UI Kit has no component for what you need — the common case, see below
- "build my own chat UI" · "just give me the data layer" · "sendMessage in React Native"
- "duplicate messages" · "listener leak" · "how do I page through history"
Prerequisites & install
The SDK ships under the UI Kit — if core is installed, so is this. A headless-only app
installs it alone:
npm install @cometchat/chat-sdk-react-native@4 @react-native-async-storage/async-storage@^2.1.2
⚠️ Not @cometchat/chat-sdk-javascript — that is the web package.
The rule: UI Kit first, SDK as fallback
For any feature, check whether the UI Kit has a component (components skill + the catalog).
If it does, use it. Reach for the SDK only when it does not.
On React Native that fallback path is not rare. Kit v5 removed the detail and management screens, so these have no component at all and are pure SDK work:
| Need | Why there is no component | Map section |
|---|---|---|
| user / group details | CometChatDetails removed in v5 |
Users & groups |
| add members | CometChatAddMembers removed |
Users & groups |
| view / unban banned members | no UI surface exists at all | Users & groups |
| transfer ownership | CometChatTransferOwnership removed |
Users & groups |
| call log detail | only the list ships | Calls |
The maps — page-wise first
references/page-map.md — the primary index, page-wise like the JavaScript SDK repo:
intent → the docs page → the methods that page demonstrates → the contract facts the RN page
does not carry. 37 pages, derived from the live docs so it cannot drift. Start here.
references/method-map.md — the per-method companion for when you already know the method
and need its exact signature, return type and constraints. 80 methods, 127/127 accounted for.
Both open with the same fallback ladder, and it matters: these cover most of the SDK, not all of it, so "not listed" never means "does not exist." Rung 2 is the catalog — that, not a map, is the existence authority.
Load page-map.md for any SDK question. It answers, per method: signature, what it resolves to, what it
rejects with, prerequisites, and what it will refuse to do. That last one matters most — it records
negative facts a docs page cannot express by omission, e.g. there is no sendCardMessage(),
which an agent would otherwise invent by symmetry with the three send methods that do exist.
Each row is marked D (backed by the RN docs) or T (recovered from the .d.ts because the RN
page is thin — RN-G15). Do not present a T row as documented; it is correct, and the docs gap
is real.
Ordering — the invariant
Init (initFromSettings) must resolve before login(). login() must resolve before you fetch or
send. Anything else fails quietly rather than throwing.
import { CometChat } from "@cometchat/chat-sdk-react-native";
// DEFAULT via skills: the ai-agent / telemetry-attributed init — persists integrationSource="ai-agent"
// (RULES §Ordering), the SDK sibling of the UI Kit's initFromSettings. Web/JS settings-OBJECT form,
// NOT the classic AppSettingsBuilder + init(APP_ID, settings). initFromSettings is @nodoc (ai-agent-only).
await CometChat.initFromSettings({
appId: APP_ID,
region: REGION,
credentials: { authKey: AUTH_KEY }, // dev only; prod logs in with an auth token
chatSDK: { presenceSubscription: { type: "ALL_USERS" } }, // = the old .subscribePresenceForAllUsers()
});
await CometChat.login(UID, AUTH_KEY); // dev only; production passes an auth token
// FALLBACK only (non-skills / doc-following context) — the publicly-documented classic path:
// const settings = new CometChat.AppSettingsBuilder()
// .setRegion(REGION).subscribePresenceForAllUsers().autoEstablishSocketConnection(true).build();
// await CometChat.init(APP_ID, settings);
⚠️ login is variadic and untyped in the .d.ts (login(...args: any)), so TypeScript will
not catch a wrong call. The two real shapes are login(uid, authKey) and login(authToken).
Listener lifecycle — the defect this skill exists to prevent
useEffect(() => {
const id = "chat-screen";
CometChat.addMessageListener(id, new CometChat.MessageListener({
onTextMessageReceived: (m) => setMessages((prev) => [...prev, m]),
}));
return () => CometChat.removeMessageListener(id); // NOT optional
}, []);
addMessageListener returns void, not a subscription — the string id is your only handle. The
SDK holds the listener, not React, so it survives navigation and unmount. Omitting the cleanup is
the top cause of duplicate messages, and it worsens the longer the app runs.
Fetching is always a builder
Lists are paginated: new CometChat.XRequestBuilder().setLimit(n).build() then .fetchNext().
An empty array means the end — it does not throw. There is no bare getMessages().
Common pitfalls
- Dropping the listener cleanup — duplicate messages that grow over time.
- Calling a bare
sendMessage()— everything is namespaced underCometChat. - Inventing
sendCardMessage()— card messages are receive-only. awaitingstartTyping— it returns void.- Treating
getLoggedinUser()returningnullas an error — it is the normal no-session answer. (Note the lowercasein.) - Shipping ban without unban —
CometChatGroupMembersshows active members only; wireBannedMembersRequestBuilder+unbanGroupMembertoo. - Registering a push token before
loginresolves — it belongs to no user.
Verify it works
- Every symbol appears in
catalogs/rn-sdk-v4.json. npm run verify:fences:rn-v5is green.- Every
add*Listenerhas a matchingremove*Listeneron the teardown path. - Pagination, error handling and the ban round trip are wired — not just the happy path.
04 同仓库更多 Skills
migrate-to-e2e
Moves an existing Playwright, Cypress, Selenium, Appium, Detox, Maestro, or TesterArmy suite to e2e one slice at a time, with the old suite running beside the new one until each ported test is proven. Keeps a MIGRATION.md progress file so any later session resumes where the last stopped. Optionally plants a defect to show both suites catch it. Use for /migrate-to-e2e, "migrate our tests to e2e", "port these Maestro flows", "move our TesterArmy tests", or when a project has an e2e config and an older suite still running.
e2e
Writes, runs, and debugs end-to-end tests for web and mobile apps with e2e, the agentic test runner, which mixes agent.act goals with exact locator assertions on a Playwright browser or an iOS or Android device. Also drives a project's running app live over the e2e MCP server to look at a screen, check a UI change, take a screenshot or record a video, and try a locator; and runs bug bashes, parallel e2e explore runs with each bug proven by a repro test. Use when a project depends on e2e or has an e2e.config.ts, when asked for end-to-end, browser, mobile, or agentic UI tests, to check a change in the running app, to QA or bug bash an app or branch, or when an e2e run fails.
create-verification-skill
Generate a project-local verify-<app> skill on top of e2e, so any coding agent can launch the app, check it is worth driving, exercise a feature the way a user does, keep evidence, and bug bash it. Writes the skill, a feature map with one explore charter per feature, and proves it once. Use for /create-verification-skill, "make a verification skill for this repo", or when a project has no scripted way to prove UI behavior.
deja-search
deja-vu memory — search the user's past AI coding sessions with the deja CLI. Holds what they already settled and never wrote into the repo (naming rules, banned or already-tried tools, required checks before merge, preferred values, who owns what). Use before your first edit in a task, before you call a change done or ready to merge, before you recommend a tool, library, design or reviewer, before re-debugging an error that may already be solved, when they say 'didn't we fix this before', 'what did we decide about X' or 'I already have that', and before telling them something on this machine does not exist.
deja-reflect
End-of-session reflection and memory curation with deja-vu. Review what was decided, what commands broke and what repaired them, and record durable project rules or decisions with deja remember so the next session starts with them.
revid
Make, edit, export and post AI videos with Revid (revid.ai) through the Revid MCP server. Use whenever the user wants a short-form or long-form video made (from an idea, a script, a URL, an article, a PDF, a tweet, a product page, their own clips, or a song), wants to find what is going viral on TikTok, YouTube, Instagram or X before making something, wants to edit or re-export an existing Revid project, generate a standalone AI image or clip, make a series episode, or publish and schedule a finished video to connected social accounts. Covers setup (hosted MCP with OAuth, or an API key), the 36 tools, credits, polling and the rules for publishing. Routes to the more specific revid-* skills when one fits.