Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xranx OpenContext useDataIntegrity

From Leeroopedia
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

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();
    }
  }, []);
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment