@cstar.help/react v0.13.0

Spell Tome of the React SDK

“With great power comes great refetch.”

Providers

'use client';
import { CStarChatProvider, CStarLibraryProvider } from '@cstar.help/react';

export function Providers({ children }) {
  // Seeded with a test key (cstar seed)? Add publishableKey="pk_test_..." to read test articles.
  return (
    <CStarLibraryProvider teamSlug="acme">
      <CStarChatProvider teamSlug="acme">
        {children}
      </CStarChatProvider>
    </CStarLibraryProvider>
  );
}

Both providers are 'use client'. Mount at your client boundary.

Library hooks

const { categories } = useCategories();
const { articles, refresh } = useArticles({ categorySlug: 'billing' });
const { article } = useArticle(slug);
const { results, totalCount } = useArticleSearch(query);

Public, no auth. Safe everywhere in the tree.

Chat hooks

const { isIdentified, identify, disconnect } = useChat();

const { tickets, create } = useTickets(); // no filters

const { messages, send } = useMessages(ticketId);
const { typingAgents } = useTyping(ticketId);

Identify

// Server: sign the customer payload with your chat-secret
import { createHmac } from 'node:crypto';
// Sign the defined fields with keys sorted A to Z
const signed = Object.fromEntries(
  Object.entries(customer).filter(([, v]) => v !== undefined).sort(([a], [b]) => a.localeCompare(b))
);
const sig = createHmac('sha256', secret).update(JSON.stringify(signed)).digest('hex');

// Client
const { identify } = useChat();
await identify(customer, sig);

Gotchas

  • Always wrap in providers. The hooks throw if no context is found.
  • Hooks fetch in the browser. Loading state during SSR; data after mount.
  • useMessages auto-subscribes to realtime on mount; tear-down on unmount is automatic.
  • RSC: mount providers in a 'use client' boundary, not inside a Server Component.
  • Turbopack HMR warnings in Next 16 dev console are upstream, not the SDK.

Hook return shape

  • data / tickets / articles: array, empty until fetched.
  • isLoading: boolean. True during initial fetch + refetches.
  • error: Error | null.
  • refresh(): Promise. Fetches again.
  • create() / send(): Promise. Adds the result to the list.