Documentation Index
Fetch the complete documentation index at: https://mintlify.com/davidmpizarro/QuipuEco-Hackaton/llms.txt
Use this file to discover all available pages before exploring further.
useHistorial is the single source of truth for recycling activity in QuipuEco. It persists every AI classification result to localStorage, exposes a prepend-only history array ordered newest-first, and derives five computed statistics—including eco-rank points—on every render without requiring Redux, Zustand, or any other external state library. Any component that needs historical data or wants to write a new record simply calls this hook.
Import and usage
App.jsx, which then passes derived values down to ImpactDashboard and records down to ClassificationResult.
Return value
An array of classification records, ordered newest-first. Each entry is the merged result of a
/clasificar API response and the two fields added by agregarRegistro (id and fecha). Initialized from localStorage on first render; falls back to [] if the key is missing or the JSON is malformed.Prepends a new record to
historial and synchronously persists the updated array to localStorage.Parameters:resultado— the full JSON object returned by the/clasificarendpointimagen— theblob:URL string produced byURL.createObjectURL()for the selected or captured image
Resets
historial to an empty array by calling setHistorial([]). The persistence useEffect then fires and writes [] to localStorage under the key quipueco_historial. Used by ImpactDashboard when the user taps Limpiar Historial.A computed statistics object derived from the current
historial array on every render. See the full field breakdown below.Record structure
Every entry inhistorial—and the object returned by agregarRegistro—has the following shape. The id and fecha fields are injected by the hook; all other fields are spread directly from the /clasificar API response.
| Field | Source | Notes |
|---|---|---|
id | Date.now() | Millisecond timestamp, used as React key |
fecha | new Date().toISOString() | ISO 8601 string in UTC |
imagen | Caller-supplied | Blob URL — see note below |
nombre | /clasificar response | Human-readable item name |
tipo | /clasificar response | Material category slug |
co2_evitado_kg | /clasificar response | May be 0 or absent for non-recyclables |
peso_estimado_kg | /clasificar response | Estimated item weight |
instrucciones | /clasificar response | Locale-specific disposal instructions |
punto_acopio | /clasificar response | Suggested drop-off network name |
consejo | /clasificar response | Eco tip shown on the result card |
respuesta_voz | /clasificar response | Text read aloud by the browser TTS engine |
Persistence
The hook uses auseEffect that fires whenever historial changes, writing the serialized array to localStorage under the key quipueco_historial. Initialization reads the same key inside the useState lazy initializer, so history is restored synchronously before the first render—no flash of empty state.
Example: eco-rank tier check
Usestats.puntos to determine which rank tier a user has reached. The ImpactDashboard component uses the same thresholds to render a progress bar.
The
imagen field in each record stores a blob: URL created with URL.createObjectURL() at capture time. Blob URLs are session-scoped—they are revoked when the browser tab closes. On the next page load, historial will be restored from localStorage with all metadata intact, but the imagen value will be a stale blob reference that no longer resolves to an image. The ImpactDashboard history list renders a broken thumbnail in this case. If persistent thumbnails are required, encode the image as a Base64 data URL before passing it to agregarRegistro.