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 windowisPendingmeans the debounce timer is activeisScanningmeansclient.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 sessionclearSession(id)removes oneclearAll()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:
- Call
initialize(text, entities)after detection. - Let users edit replacements or remove items.
- Show
previewas a live processed-text preview. - Call
finalize()to create aFinalizedTextReviewand 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
| Need | Hook |
|---|---|
| Run detection from a button click | useDetect() |
| Run debounced detection from typing | useScan() |
| Obfuscate then optionally restore in the same component | useObfuscate() |
| Restore in a different component using a known session ID | useRestore() |
| Reactively inspect and clear active sessions | useSessions() |
| Detect PII in uploaded files | useFileDetect() |
| Produce an obfuscated output file | useFileObfuscate() |
| Let a user edit replacements before obfuscating | useTextReview() |
| Work with thread/global vault state | useVault() |