Hooks

Drop-in replacements for React hooks with chaos injection.

Every hook accepts an optional options object as its last argument. All options extend HookMetadata:

FieldTypeDescription
namestringIdentifier for targeting and logging
componentstringEnclosing component name
probabilitynumberOverride the default probability (0–1)
failuresstring[]Allowed failure modes for this hook

useVolatileState

const [state, setState] = useVolatileState(initialState, options?)

Wraps useState. Chaos is injected when the setter is called.

FailureBehavior
delayState update is applied after a random delay
errorThrows a VolatileError
corruptApplies a corrupted value instead of the real one

Custom Corruptor

const [name, setName] = useVolatileState('hello', {
  failures: ['corrupt'],
  corruptor: (value) => value.toUpperCase() + '!!',
});

useVolatileEffect

useVolatileEffect(effect, deps, options?)

Wraps useEffect. Chaos is injected when the effect runs.

FailureBehavior
delayEffect execution is delayed
errorThrows a VolatileError
skipEffect is skipped entirely
useVolatileEffect(() => {
  fetchData();
  return () => cleanup();
}, [id], {
  name: 'fetchData',
  component: 'UserProfile',
  failures: ['delay', 'skip'],
});

useVolatileLayoutEffect works identically but wraps useLayoutEffect.

useVolatileReducer

const [state, dispatch] = useVolatileReducer(reducer, initialState, options?)

Wraps useReducer. Chaos is injected when dispatch is called.

FailureBehavior
delayDispatch is applied after a random delay
errorThrows a VolatileError

useVolatileMemo

const value = useVolatileMemo(factory, deps, options?)

Wraps useMemo. Chaos is injected during memoization.

FailureBehavior
errorThrows a VolatileError

useVolatileCallback

const fn = useVolatileCallback(callback, deps, options?)

Wraps useCallback. Chaos is injected when the returned function is called.

FailureBehavior
errorThrows a VolatileError
delayCallback returns a Promise that resolves after a delay
noopCallback does nothing, returns undefined

useVolatileAsync

const { data, error, loading, execute } = useVolatileAsync(asyncFn, options?)

Wraps an async function with loading/error state management and chaos injection.

FailureBehavior
delayAdds a random delay before executing
rejectRejects with a VolatileError
timeoutWaits 3x the delay range then rejects
const { data, error, loading, execute } = useVolatileAsync(
  () => fetch('/api/users').then(r => r.json()),
  { name: 'fetchUsers', failures: ['delay', 'reject'] },
);

// call execute() to run the async function
<button onClick={() => execute()}>Load</button>

useChaosTrigger

const { trigger, isActive, engine } = useChaosTrigger()

Manual control hook. Does not wrap any React hook — use it to emit chaos events programmatically.

trigger({
  type: 'state',
  failure: 'error',
  target: 'manualTest',
  component: 'DebugPanel',
});