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
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
Asynchronously loads all records from the service and updates the state. Called automatically on mount.
Creates a new record with the specified title and type. Automatically reloads records after creation.Throws an error if creation fails.
Updates an existing record. Accepts a complete Record object with modified fields. Automatically reloads records after update.Throws an error if update fails.
Deletes a record by ID. Automatically reloads records after deletion.Throws an error if deletion fails.
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