Skip to Content
Hooks

useKivaEmailComposer

Wires the native EmailComposer to the Kiva messaging API — sender accounts, @ mention users and the send mutation, with composer state managed for you.

iOSAndroidExpo Go

Installation

pnpm dlx @kivacore/ui-cli add @kivacore/rn-hooks-use-kiva-email-composer
Required Packages(2 packages)
pnpm add @tanstack/react-query @kivacore/api-client

A verbatim port of the web hook (same options, result and query keys). It fetches GET /v1/messaging/email/accounts for the From picker and auto-selects the first user-accessible account, fetches GET /v1/users once for @ mentions (client-side filtering), and sends through POST /v1/messaging/email/accounts/{accountId}/send. It returns composerProps to spread onto EmailComposer. Both endpoints need the Messaging.Email.Send scope, and a QueryClientProvider must be mounted above it.

Usage

import { EmailComposer } from '@/components/kiva-native/email-composer';
import { useKivaEmailComposer } from '@/hooks/kiva-native/use-kiva-email-composer';

function ReplyComposer({ client, to }) {
  const { composerProps, send, attachments } = useKivaEmailComposer({ client, initialTo: to });

  return (
    <EmailComposer
      {...composerProps}
      attachments={attachments}
      onSend={async () => {
        const result = await send({ attachments: [{ filePath: uploaded.fullPath, fileName: 'quote.pdf' }] });

        console.log(result.accepted, result.rejected);
      }} />
  );
}

send(overrides) takes storage-backed attachments ({ filePath, fileName?, mimeType? }) — upload the picked NativeFile to Kiva storage first. The composer's own attachments ({ name, size }) are display metadata only.

API Reference

UseKivaEmailComposerOptions

OptionTypeDefaultDescription
clientRestApiClient-Authenticated REST client (required)
initialTo / initialCc / initialBcc / initialReplyTostring[][]Initial recipients
initialSubjectstring''Initial subject
initialBodystring''Initial HTML body
initialAccountIdstringfirst accessibleAccount to preselect
resetOnSendSuccessbooleantrueClear recipients / subject / body / attachments after a send
enabledbooleantrueToggle the queries
sendAsUserboolean-Default sendAsUser for every send
listAccountsEndpointstring/v1/messaging/email/accountsAccounts endpoint
sendEndpointstring/v1/messaging/email/accounts/{accountId}/sendSend endpoint
mentionsbooleantrueFetch /v1/users for mentions
mentionUsersEmailComposerMentionUser[]-Explicit mention users (skips the fetch)
listUsersEndpointstring/v1/usersUsers endpoint
slashCommandsEmailComposerSlashCommand[]-Passed through to the composer

UseKivaEmailComposerResult

FieldTypeDescription
composerPropsPick<EmailComposerProps, …>accounts, selection, to / cc / bcc, subject, body, mentionUsers, slashCommands, onSend, sending
accounts / selectedAccountKivaEmailAccount[] / KivaEmailAccount | nullRaw account DTOs
setSelectedAccountId(id: string) => voidChange the account
isLoadingAccounts / accountsError / refetchAccountsAccounts query state
mentionUsersEmailComposerMentionUser[]Resolved mention users
to / cc / bcc / replyTo / subject / body / attachments + settersComposer state
send(overrides?: KivaEmailSendOverrides) => Promise<KivaEmailSendResult>Send
isSending / sendError / lastSendResultMutation state
reset() => voidRestore the initial values

Types

TypeDescription
KivaEmailAccountAccount DTO (kind, provider, providerSlug, isUserAccessible, allowOverrideName, allowOverrideEmail, createdOn)
KivaEmailAttachment{ filePath, fileName?, mimeType? }
KivaEmailSendOverridesPer-send to, cc, bcc, replyTo, subject, body, sendAsUser, attachments, accountId
KivaEmailSendResult{ messageId, provider, accepted, rejected }
KivaEmailProvider'aws' | 'smtp' | 'mailgun' | 'resend' | 'microsoft-graph' | 'gmail'

On this page