react-redact

RedactProvider

Context provider and global redact config.

RedactProvider

Wraps your app (or a subtree) to provide redact state and config. Listens for the keyboard shortcut and toggles enabled.

Usage

import { RedactProvider } from 'react-redact';
import 'react-redact/styles.css';

<RedactProvider
  mode="blur"
  shortcut="mod+shift+x"
  enabled={false}
  autoDetect={['email', 'phone']}
  customPatterns={[/ACME-\d{6}/g]}
>
  <App />
</RedactProvider>

Props

PropTypeDefaultDescription
childrenReactNodeApp or subtree
mode'blur' | 'mask' | 'replace' | 'custom''blur'Default redaction style
shortcutstring'mod+shift+x'Keyboard shortcut; mod = ⌘/Ctrl
enabledbooleanfalseInitial redact state
autoDetectfalse | BuiltInPatternName[]falsePattern names for context (e.g. useRedactPatterns)
customPatternsRegExp[]Extra patterns for context
customRender(props: { children, text }) => ReactNodeDefault renderer for <Redact mode="custom"> when no renderRedacted

When enabled changes, the provider toggles the react-redact-blur class on all [data-redact] elements so auto-injected spans stay in sync.