Overview
TheuseDailyRecord hook provides complete CRUD (Create, Read, Update, Delete) operations for daily health records. It allows users to track and manage their daily health data including mood, symptoms, and other vitals.
Hook Signature
Return Value
The hook returns an object containing the following functions:Functions
getDailyRecord
userId(string/number): The ID of the user
- On success: Array of daily record objects
- On error: Error message string
createDailyRecord
recordData(Object): Daily record data including:userId(string/number): User ID- Health metrics (mood, symptoms, vitals, etc.)
date(string): Record date
- Response object from the service with
okstatus and data/error message
deleteDailyRecord
id(string/number): Daily record ID to delete
- On success: Deleted record data object
- On error: Error message string
updateDailyRecord
id(string/number): Daily record ID to updaterecordData(Object): Updated record data
- Response object from the service with
okstatus and data/error message
Usage Example
Complete CRUD Example
Dependencies
This hook requires:dailyRecordServicefor API calls:getDailyRecordsByUserID: Fetch records by user IDcreateDailyRecordService: Create a new recordupdateDailyRecordService: Update an existing recorddeleteDailyRecordService: Delete a record by ID
Notes
- All functions use
useCallbackfor optimization createDailyRecordandupdateDailyRecordreturn the full service response object withokanddata/messageErrorpropertiesgetDailyRecordanddeleteDailyRecordreturn simplified responses (data or error message)- Components should handle loading states and error messages
- The hook does not maintain internal state - components manage their own state
