Overview
TheuseRecords 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 identifiertitle: string - Record titlesubtitle?: string - Optional subtitlemetadata?: string - Optional metadatatype: string - Record typeuserId?: string - Optional user IDcreatedAt: string - Creation timestampupdatedAt: string - Last update timestampisDeleted: 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
RecordServiceinternally for data operations - Errors are caught and re-thrown with formatted messages using
getErrorMessage
Source
Defined insrc/presentation/hooks/useRecords.ts:6