Skip to main content
The @retab/react package exports several React hooks for accessing Retab context and data. These hooks must be used within a RetabProvider.

useProject

Access the current project’s data and configuration.

Returns

PropertyTypeDescription
projectProjectThe current project object
applyComputations(data: any) => Promise<any>Apply computed fields to extraction data

Example

useProject Example

useExtractions

Access the extractions list and selection state. This hook requires the ExtractionsProvider to be enabled (default).

Returns

PropertyTypeDescription
extractionsExtraction[]List of extractions
selectedExtractionIdstring | nullCurrently selected extraction ID
setSelectedExtractionId(id: string | null) => voidSet the selected extraction

Example

useExtractions Example

useOptionalExtractions

Same as useExtractions, but returns null if the extractions context is not available. Useful for components that may be used outside the extractions provider.

Example

useOptionalExtractions Example

useExtraction

Fetch a single extraction by ID. Returns the extraction data and loading state.

Parameters

ParameterTypeDescription
extractionIdstring | nullThe extraction ID to fetch

Returns

PropertyTypeDescription
dataExtraction | nullThe extraction object
isLoadingbooleanWhether the extraction is loading
errorError | nullError if the fetch failed

Example

useExtraction Example

useExtractionList

Query extractions with filters, pagination, and sorting. Returns a React Query result.

Parameters

ParameterTypeDescription
optionsExtractionListOptionsQuery options

ExtractionListOptions

OptionTypeDescription
origin_dot_idstringProject ID to filter by
limitnumberNumber of items per page
order"asc" | "desc"Sort order
beforestringCursor for previous page
afterstringCursor for next page
filenamestringFilter by filename (search)
from_datestringFilter by start date (YYYY-MM-DD)
to_datestringFilter by end date (YYYY-MM-DD)
metadataRecord<string, string>Filter by metadata

Returns

PropertyTypeDescription
data{ data: Extraction[], list_metadata: PaginationMetadata }Query result
isLoadingbooleanWhether the query is loading
errorError | nullError if the query failed
refetch() => voidRefetch the data

Example

useExtractionList Example

useJsonSchema

Access the current project’s JSON schema, including computed fields.

Returns

PropertyTypeDescription
computedSchemaExtendedJSONSchema7Schema with computed fields included
jsonSchemaExtendedJSONSchema7Original schema without computed fields

Example

useJsonSchema Example

useAuth

Access the authentication context for making authenticated API requests.

Returns

PropertyTypeDescription
fetchWithAuth(url: string, options?: RequestInit) => Promise<Response>Fetch function with auth headers
isAuthenticatedbooleanWhether the user is authenticated

Example

useAuth Example

useOCR

Access OCR context for field location detection and source highlighting.

Returns

PropertyTypeDescription
getFieldSources(extractionId: string, fieldPath: string) => Source[]Get OCR sources for a field
isLoadingbooleanWhether OCR data is loading

Example

useOCR Example

Type Definitions

Extraction

Extraction

PaginationMetadata

PaginationMetadata