Implementation:0xranx OpenContext useDataIntegrity
| Knowledge Sources | |
|---|---|
| Domains | Data_Integrity, React |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
React hook and utility functions for data integrity management, validating folder trees, cleaning stale caches, and managing URL state persistence.
Description
The useDataIntegrity.js hook in src/ui/src/hooks/ provides a validate function that fetches the folder tree and collects all valid paths, a shouldCleanupOnError check for not-found errors, cleanStaleFolders to prune expanded/docs state against valid paths, and resetAllCache for full reset. It also exports standalone utilities: collectFolderPaths (recursive path set builder), clearLastUrl, saveLastUrl, and restoreLastUrl for localStorage-based URL persistence.
Usage
Import this hook in App.jsx or SidebarTree to validate data on load and clean up stale state after folder deletions.
Code Reference
Source Location
- Repository: 0xranx_OpenContext
- File: src/ui/src/hooks/useDataIntegrity.js
- Lines: 1-161
Signature
export function useDataIntegrity({ api })
export function collectFolderPaths(folders, prefix = '')
export function clearLastUrl()
export function saveLastUrl()
export function restoreLastUrl()
Import
import { useDataIntegrity, collectFolderPaths, clearLastUrl } from './hooks/useDataIntegrity';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| api | object | Yes | API abstraction with listFolders |
Outputs
| Name | Type | Description |
|---|---|---|
| validate | async Function | Returns { isValid, folders, validPaths, error } |
| shouldCleanupOnError | Function | Returns true if error is not-found |
| cleanStaleFolders | Function | Returns pruned { expandedFolders, folderDocs } |
| resetAllCache | Function | Returns initial empty state |
Usage Examples
Validating Data
import { useDataIntegrity } from './hooks/useDataIntegrity';
function App() {
const { validate, cleanStaleFolders, resetAllCache } = useDataIntegrity({ api });
useEffect(() => {
const result = await validate();
if (!result.isValid) {
resetAllCache();
}
}, []);
}