Overview
TheuseScan() hook is the React hook version of the scan() function. It allows you to initialize React Scan within a React component.
Signature
Parameters
Optional configuration object to customize React Scan behavior. See Options for all available settings.
Returns
void - This hook does not return a value.
Usage
Basic Usage
With Options
Conditional Scanning
With Custom Callbacks
Comparison with scan()
| Feature | scan() | useScan() |
|---|---|---|
| Usage context | Anywhere in JavaScript | Inside React components only |
| Timing | Runs immediately when called | Runs during component mount |
| Typical usage | Module-level initialization | Component-level initialization |
Both
scan() and useScan() call the same underlying initialization logic. Choose based on your preferred initialization pattern.Best Practices
- Call
useScan()in your root component (e.g.,App.tsx) for consistent behavior - Don’t call
useScan()in multiple components - it only needs to be called once - Use the
enabledoption to control when scanning is active
See Also
- scan() - Imperative version of useScan()
- setOptions() - Update options at runtime
- Options - Full options reference