Secured

Hooks

Reference for the React hooks exported by @secured-ai/react.

Text hooks

useDetect()

Imperative, one-shot text detection.

const { detect, data, isPending, error, reset } = useDetect()

Use it for submit-driven flows where you want a promise back and also want React state for the latest result.

useScan(options?)

Debounced detection for input-driven experiences.

const { scan, data, entities, sensitiveEntities, isScanning, isPending, error, reset } =
  useScan({ debounce: 300, enabled: true })
  • scan(text) starts or restarts the debounce window
  • isPending means the debounce timer is active
  • isScanning means client.detect() is currently running

This is the best fit for live textareas, editors, and form fields.

useObfuscate()

Combined obfuscation and restoration hook with tracked session state.

const {
  obfuscate,
  restore,
  lastResult,
  sessionId,
  isPending,
  error,
  reset,
} = useObfuscate()

restore(processedText) uses the most recent session automatically. Pass an explicit session ID to override that default.

useRestore()

Restoration-only hook that always requires an explicit session ID.

const { restore, data, isPending, error, reset } = useRestore()

Use it when the component performing restore is different from the one that originally obfuscated the text.

useSessions()

Reactive view over the client's in-memory sessions.

const { sessions, clearSession, clearAll } = useSessions()

This updates when:

  • useObfuscate() creates a new session
  • clearSession(id) removes one
  • clearAll() removes all sessions

File hooks

useFileDetect()

Detects PII in browser File objects.

const { detectInFile, data, isPending, error, reset } = useFileDetect()

The returned data is a FileProcessingResult with:

  • extracted text
  • detected entities
  • file type metadata
  • processing time

useFileObfuscate()

Creates an obfuscated file as a Blob.

const { obfuscateFile, data, isPending, error, reset } = useFileObfuscate()

You can pass a second entities argument if your UI already reviewed detections and you want to skip re-detection.

Advanced hooks

useTextReview()

Builds human-in-the-loop review UIs where users can edit replacements before finalizing.

const {
  review,
  items,
  preview,
  lastFinalized,
  initialize,
  setReplacement,
  removeItem,
  restoreItem,
  addEntity,
  finalize,
  hydrate,
  reset,
} = useTextReview()

Typical flow:

  1. Call initialize(text, entities) after detection.
  2. Let users edit replacements or remove items.
  3. Show preview as a live processed-text preview.
  4. Call finalize() to create a FinalizedTextReview and a persisted session.

finalize() also makes the new session visible to useSessions().

useVault()

Exposes the underlying VaultManager plus a React state snapshot for vault status.

const {
  vault,
  status,
  getGlobalSnapshot,
  getThreadSnapshot,
  getRuntimeThreadEntries,
  getPendingEntries,
  setThreadContext,
  refreshContext,
} = useVault()

Use this when your app needs:

  • thread-aware replacement reuse
  • access to cached global or thread snapshots
  • namespace refresh after auth or workspace changes
  • direct access to advanced vault methods like vault.deobfuscate()

useVault() must be used inside SecuredProvider.

Choosing the right hook

NeedHook
Run detection from a button clickuseDetect()
Run debounced detection from typinguseScan()
Obfuscate then optionally restore in the same componentuseObfuscate()
Restore in a different component using a known session IDuseRestore()
Reactively inspect and clear active sessionsuseSessions()
Detect PII in uploaded filesuseFileDetect()
Produce an obfuscated output fileuseFileObfuscate()
Let a user edit replacements before obfuscatinguseTextReview()
Work with thread/global vault stateuseVault()

On this page