Description
useScan() unconditionally calls start() regardless of the enabled option, unlike scan() which properly guards against it.
// scan() — respects enabled ✅
export const scan = (options: Options = {}) => {
setOptions(options);
if (options.enabled === false && options.showToolbar !== true) {
return;
}
start();
};
// useScan() — ignores enabled ❌
export const useScan = (options: Options = {}) => {
setOptions(options);
start(); // always runs regardless of enabled
};
Reproduction
import { useScan } from "react-scan";
function App() {
useScan({ enabled: false }); // scanning still activates
return <div>Hello</div>;
}
Expected Behavior
When enabled: false is passed to useScan(), scanning and the toolbar should not activate — matching the behavior of scan().
Related
Proposed Fix
Apply the same iframe and enabled guards from scan() to useScan():
export const useScan = (options: Options = {}) => {
setOptions(options);
const isInIframe = Store.isInIframe.value;
if (
isInIframe &&
!ReactScanInternals.options.value.allowInIframe &&
!ReactScanInternals.runInAllEnvironments
) {
return;
}
if (options.enabled === false && options.showToolbar !== true) {
return;
}
start();
};
Branch with the fix: https://github.com/jalbarrang/react-scan/tree/fix/usescan-respects-enabled
Note: Unable to open a PR since the repo restricts PRs to collaborators.
Description
useScan()unconditionally callsstart()regardless of theenabledoption, unlikescan()which properly guards against it.Reproduction
Expected Behavior
When
enabled: falseis passed touseScan(), scanning and the toolbar should not activate — matching the behavior ofscan().Related
enabledguard toscan()but never applied it touseScan()Proposed Fix
Apply the same iframe and
enabledguards fromscan()touseScan():Branch with the fix: https://github.com/jalbarrang/react-scan/tree/fix/usescan-respects-enabled