@coin-communities/sdk/react-query ships hook bindings around every operation in the SDK Reference, an optimistic-post reconciliation hook, plus a queryKeys factory for cache invalidation and prefetching. The entry also re-exports configureApi and the api namespace, so it's the only import path most React apps need.
Wrap your app in a QueryClientProvider and configure the SDK once at boot:
import { configureApi } from '@coin-communities/sdk/react-query';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';configureApi({ baseUrl: 'https://api.coin-communities.xyz', auth: () => getToken(),});const queryClient = new QueryClient();export function App({ children }: { children: React.ReactNode }) { return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;}
Conventions
Read operations (GET) are exposed as useXxx() hooks returning UseQueryResult<TData, TError>.
Write operations (POST / PUT / DELETE) are exposed as useXxx() hooks returning UseMutationResult<TData, TError, TVars>.
Hooks accept the standard React Query options object as their last argument (onSuccess, onError, select, enabled, …) — query/mutation keys and functions are managed for you.
Mutations that target a single resource (e.g. useRotateApiKey) take the resource id as the mutation variable rather than an options object.
Hooks scoped to a community (useMessages, usePostMessage, …) take tokenAddress as the first positional argument.
mutation (PostMessageRequest) — auto-invalidates replies list
Community Members
Hook
Wraps
Kind
useCommunityMembers(tokenAddress, params?, opts?)
api.getCommunityMembers()
query
Realtime
useOptimisticCommunityPosts is the recommended companion to usePostMessage.
It creates pending Message objects, subscribes to realtime events, reconciles
clean or moderated message_update events, invalidates the message cache on
resolution/gaps, and exposes mergePendingPosts(fetched) for rendering.
import { useOptimisticCommunityPosts } from '@coin-communities/sdk/react-query';const optimistic = useOptimisticCommunityPosts(tokenAddress, { auth: { getTicket: async () => { const { data } = await api.getWsTicket({ path: { token_address: tokenAddress } }); if (!data?.ticket) throw new Error('WebSocket ticket unavailable'); return data.ticket; }, }, author: { userId: me.id, username: me.username }, onReject: () => toast.error('Your post was removed by moderation.'), onModeration: () => toast.error('Your post was removed by moderation.'),});const feed = optimistic.mergePendingPosts(messages.data?.messages ?? []);
Use the lower-level realtime hooks from @coin-communities/sdk/react when you
want to handle raw message_update, like_update, moderation_update, and
onGap events yourself.
Business — API Key Origins
Hook
Wraps
Kind
useApiKeyOrigins(apiKeyId, opts?)
api.listApiKeyOrigins()
query
useAddApiKeyOrigin(opts?)
api.addApiKeyOrigin()
mutation (AddApiKeyOriginVariables) — auto-invalidates origins list
useRemoveApiKeyOrigin(opts?)
api.removeApiKeyOrigin()
mutation (RemoveApiKeyOriginVariables) — auto-invalidates origins list
queryKeys factory
queryKeys is a stable, typed object literal that exposes the cache key for every query the hooks use. Reach for it when you want to invalidate, prefetch, or read cache entries directly.