useDateFormat
Provider-agnostic date, datetime and time formatting context for Docyrus native components. Wired automatically by DocyrusTenantProvider, but works with any date library.
Installation
pnpm dlx @docyrus/cli add @docyrus/rn-hooks-use-date-formatThe module exports useDateFormat() (hook), <DateFormatProvider> (provider), isDefaultDateFormatContext() and DateFormatContext. It has no runtime dependencies. The formatter comes from you or from a parent <DocyrusTenantProvider>.
Overview
useDateFormat() is the read side of a small context. Components call it to get { formatDate, formatDateTime, formatTime }. The provider above them decides how formatting happens.
- No provider mounted: the hook returns a built-in sentinel that renders raw strings. Strings pass through
String(value),Dateobjects through.toISOString(),null/undefinedbecome''. <DocyrusTenantProvider>mounted: the formatters are backed by the tenant'sdateUtilsfrom@docyrus/app-utils, so values follow the tenant'sdateFormat,dateTimeFormatand time zone.- Custom provider mounted: wrap date-fns, dayjs, Luxon or
Intlwith<DateFormatProvider>.
Usage
Consume in a component
import { Text } from 'react-native';
import { useDateFormat } from '@/hooks/docyrus-native/use-date-format';
export function EventRow({ startsAt }: { startsAt: string }) {
const { formatDateTime } = useDateFormat();
return <Text>{formatDateTime(startsAt)}</Text>;
}Custom provider (date-fns)
import { format } from 'date-fns';
import { DateFormatProvider } from '@/hooks/docyrus-native/use-date-format';
export function AppProviders({ children }: { children: React.ReactNode }) {
return (
<DateFormatProvider
formatDate={v => format(new Date(v as string), 'dd/MM/yyyy')}
formatDateTime={v => format(new Date(v as string), 'dd/MM/yyyy HH:mm')}
formatTime={v => format(new Date(v as string), 'HH:mm')}>
{children}
</DateFormatProvider>
);
}API Reference
useDateFormat()
Takes no parameters. Returns: DateFormatContextValue.
| Field | Type | Description |
|---|---|---|
formatDate | (value: unknown) => string | Date-only output. |
formatDateTime | (value: unknown) => string | Date and time output. |
formatTime | (value: unknown) => string | Time-only output. |
<DateFormatProvider>
| Prop | Type | Default | Description |
|---|---|---|---|
formatDate | DateFormatFn | — | Required. Backs formatDate inside the tree. |
formatDateTime | DateFormatFn | — | Required. Backs formatDateTime inside the tree. |
formatTime | DateFormatFn | — | Required. Backs formatTime inside the tree. |
children | ReactNode | — | Tree to wrap. |
isDefaultDateFormatContext(ctx)
| Parameter | Type | Description |
|---|---|---|
ctx | DateFormatContextValue | A value returned by useDateFormat(). |
Returns: boolean. true when ctx is the no-provider sentinel rather than a real provider. Listing hooks use it so they don't shadow a cell's own fallback formatting when no provider is mounted.
DateFormatContext
The raw context (DateFormatContextValue | null, null without a provider). Native-only export: the native data-grid cell reads it directly. Prefer useDateFormat() in app code.
Type Exports
| Type | Description |
|---|---|
DateFormatFn | (value: unknown) => string. |
DateFormatContextValue | Shape returned by useDateFormat(). |
useDataExport
Client-side export of already-loaded rows to CSV, JSON, Markdown or Excel on React Native. Projects rows through a column list, writes the file into the cache directory and opens the share sheet. API-aligned with the web useDataExport.
useDocyrusAdaptiveCardItemDetail
Generate an Adaptive Card JSON payload from a Docyrus field list + a single record — mapping Docyrus field types onto the Adaptive Cards element vocabulary — and render it with the shared native AdaptiveCard renderer.