Skip to main content

Overview

The useRecords hook provides a complete interface for managing records in the application. It handles loading, creating, updating, and deleting records, with automatic data refreshing after mutations.

Signature

Return Values

Record[]
required
Array of all records. The Record type includes:
  • id: string - Unique identifier
  • title: string - Record title
  • subtitle?: string - Optional subtitle
  • metadata?: string - Optional metadata
  • type: string - Record type
  • userId?: string - Optional user ID
  • createdAt: string - Creation timestamp
  • updatedAt: string - Last update timestamp
  • isDeleted: boolean - Soft delete flag
() => Promise<void>
required
Asynchronously loads all records from the service and updates the state. Called automatically on mount.
(title: string, type: string) => Promise<void>
required
Creates a new record with the specified title and type. Automatically reloads records after creation.Throws an error if creation fails.
(record: Record) => Promise<void>
required
Updates an existing record. Accepts a complete Record object with modified fields. Automatically reloads records after update.Throws an error if update fails.
(id: string) => Promise<void>
required
Deletes a record by ID. Automatically reloads records after deletion.Throws an error if deletion fails.
(title: string) => Promise<boolean>
required
Checks if a record with the given title already exists. Useful for validation before creating new records.Returns true if a record exists, false otherwise.

Usage Example

Implementation Details

  • Records are loaded automatically when the component mounts
  • All mutation operations (create, update, remove) automatically reload the records list
  • The hook uses RecordService internally for data operations
  • Errors are caught and re-thrown with formatted messages using getErrorMessage

Source

Defined in src/presentation/hooks/useRecords.ts:6