Hooks

React hooks for accessing data and functionality

Hooks provide access to data and functionality within your custom components.

useAccounts

Access account-related data and functions.

1import { useAccounts } from "@openledger/accounting-react";
2
3function AccountList() {
4 const {
5 accounts,
6 loadingStatus,
7 createAccount,
8 updateAccount,
9 deleteAccount,
10 } = useAccounts();
11
12 // Use account data and functions...
13}
PropertyTypeDescription
accountsAccount[]Array of accounts
loadingStatus"loading" | "error" | "success"Current loading state
createAccount(account: AccountInput) => Promise<Account>Function to create an account
updateAccount(id: string, account: Partial<AccountInput>) => Promise<Account>Function to update an account
deleteAccount(id: string) => Promise<void>Function to delete an account

useTransactions

Access transaction-related data and functions.

1import { useTransactions } from "@openledger/accounting-react";
2
3function TransactionList() {
4 const {
5 transactions,
6 transactionsByMonth,
7 loadingStatus,
8 createTransaction,
9 updateTransaction,
10 deleteTransaction,
11 mutate,
12 } = useTransactions();
13
14 // Use transaction data and functions...
15}
PropertyTypeDescription
transactionsTransaction[]Array of transactions
transactionsByMonthRecord<string, Transaction[]>Transactions grouped by month
loadingStatus"loading" | "error" | "success"Current loading state
createTransaction(transaction: TransactionInput) => Promise<Transaction>Function to create a transaction
updateTransaction(id: string, transaction: Partial<TransactionInput>) => Promise<Transaction>Function to update a transaction
deleteTransaction(id: string) => Promise<void>Function to delete a transaction
mutate() => Promise<void>Function to refresh transactions

useOpenLedgerContext

Access the OpenLedgerContext within your components.

1import { useOpenLedgerContext } from "@openledger/accounting-react";
2
3function EntityInfo() {
4 const { auth, entityId, theme, apiUrl } = useOpenLedgerContext();
5
6 // Use context values...
7}
PropertyTypeDescription
authAuthStateAuthentication state
entityIdstringCurrent entity ID
themeThemeConfigCurrent theme configuration
apiUrlstringAPI URL being used

useGeneralLedger

Access general ledger data including journal entries and account balances.

1import { useGeneralLedger } from "@openledger/accounting-react";
2
3function LedgerData() {
4 const {
5 journalEntries,
6 accountBalances,
7 loadingStatus,
8 createJournalEntry,
9 updateJournalEntry,
10 deleteJournalEntry,
11 } = useGeneralLedger();
12
13 // Use ledger data and functions...
14}
PropertyTypeDescription
journalEntriesJournalEntry[]Array of journal entries
accountBalancesAccountBalance[]Array of account balances
loadingStatus"loading" | "error" | "success"Current loading state
createJournalEntry(entry: JournalEntryInput) => Promise<JournalEntry>Function to create a journal entry
updateJournalEntry(id: string, entry: Partial<JournalEntryInput>) => Promise<JournalEntry>Function to update a journal entry
deleteJournalEntry(id: string) => Promise<void>Function to delete a journal entry

useFinancialReports

Access financial report data and functions for generating reports.

1import { useFinancialReports } from "@openledger/accounting-react";
2
3function Reports() {
4 const {
5 balanceSheet,
6 incomeStatement,
7 cashFlowStatement,
8 loadingStatus,
9 generateReport,
10 } = useFinancialReports();
11
12 // Use report data and functions...
13}
PropertyTypeDescription
balanceSheetBalanceSheetBalance sheet report
incomeStatementIncomeStatementIncome statement report
cashFlowStatementCashFlowStatementCash flow statement report
loadingStatus"loading" | "error" | "success"Current loading state
generateReport(type: ReportType, params: ReportParams) => Promise<Report>Function to generate a custom report

useChatApi

Access the financial assistant chat API for natural language interactions.

1import { useChatApi } from "@openledger/accounting-react";
2
3function ChatInterface() {
4 const { messages, isLoading, sendMessage, clearMessages } = useChatApi();
5
6 // Use chat API functions...
7}
PropertyTypeDescription
messagesChatMessage[]Array of chat messages
isLoadingbooleanWhether a response is loading
sendMessage(content: string) => Promise<void>Function to send a message
clearMessages() => voidFunction to clear all messages

useFinancialOverview

Access key financial metrics and trend data for dashboard displays.

1import { useFinancialOverview } from "@openledger/accounting-react";
2
3function Dashboard() {
4 const { cashBalance, revenue, expenses, profit, trends, loadingStatus } =
5 useFinancialOverview();
6
7 // Use financial metrics...
8}
PropertyTypeDescription
cashBalancenumberCurrent cash balance
revenuenumberTotal revenue for the period
expensesnumberTotal expenses for the period
profitnumberProfit (revenue - expenses)
trends{ revenue: Trend, expenses: Trend, profit: Trend }Trend data for key metrics
loadingStatus"loading" | "error" | "success"Current loading state

useResponsive

Access responsive design utilities and screen size information.

1import { useResponsive } from "@openledger/accounting-react";
2
3function ResponsiveComponent() {
4 const { isMobile, isTablet, isDesktop, screenSize } = useResponsive();
5
6 // Use responsive information...
7}
PropertyTypeDescription
isMobilebooleanWhether the current screen size is mobile
isTabletbooleanWhether the current screen size is tablet
isDesktopbooleanWhether the current screen size is desktop
screenSize"xs" | "sm" | "md" | "lg" | "xl"Current screen size category