@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
| Property | Type | Description |
|---|---|---|
project | Project | The 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 theExtractionsProvider to be enabled (default).
Returns
| Property | Type | Description |
|---|---|---|
extractions | Extraction[] | List of extractions |
selectedExtractionId | string | null | Currently selected extraction ID |
setSelectedExtractionId | (id: string | null) => void | Set the selected extraction |
Example
useExtractions Example
useOptionalExtractions
Same asuseExtractions, 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
| Parameter | Type | Description |
|---|---|---|
extractionId | string | null | The extraction ID to fetch |
Returns
| Property | Type | Description |
|---|---|---|
data | Extraction | null | The extraction object |
isLoading | boolean | Whether the extraction is loading |
error | Error | null | Error if the fetch failed |
Example
useExtraction Example
useExtractionList
Query extractions with filters, pagination, and sorting. Returns a React Query result.Parameters
| Parameter | Type | Description |
|---|---|---|
options | ExtractionListOptions | Query options |
ExtractionListOptions
| Option | Type | Description |
|---|---|---|
origin_dot_id | string | Project ID to filter by |
limit | number | Number of items per page |
order | "asc" | "desc" | Sort order |
before | string | Cursor for previous page |
after | string | Cursor for next page |
filename | string | Filter by filename (search) |
human_review_status | string | Filter by review status |
from_date | string | Filter by start date (YYYY-MM-DD) |
to_date | string | Filter by end date (YYYY-MM-DD) |
metadata | Record<string, string> | Filter by metadata |
Returns
| Property | Type | Description |
|---|---|---|
data | { data: Extraction[], list_metadata: PaginationMetadata } | Query result |
isLoading | boolean | Whether the query is loading |
error | Error | null | Error if the query failed |
refetch | () => void | Refetch the data |
Example
useExtractionList Example
useJsonSchema
Access the current project’s JSON schema, including computed fields.Returns
| Property | Type | Description |
|---|---|---|
computedSchema | ExtendedJSONSchema7 | Schema with computed fields included |
jsonSchema | ExtendedJSONSchema7 | Original schema without computed fields |
Example
useJsonSchema Example
useAuth
Access the authentication context for making authenticated API requests.Returns
| Property | Type | Description |
|---|---|---|
fetchWithAuth | (url: string, options?: RequestInit) => Promise<Response> | Fetch function with auth headers |
isAuthenticated | boolean | Whether the user is authenticated |
Example
useAuth Example
useOCR
Access OCR context for field location detection and source highlighting.Returns
| Property | Type | Description |
|---|---|---|
getFieldSources | (extractionId: string, fieldPath: string) => Source[] | Get OCR sources for a field |
isLoading | boolean | Whether OCR data is loading |
Example
useOCR Example
Type Definitions
Extraction
Extraction
PaginationMetadata
PaginationMetadata