import { useNfcReader } from "@endstate-sdk/reader/react";
const {
isScanning,
error,
needsAuthorization,
startScanning,
stopScanning,
requestDevice,
} = useNfcReader({
onTap: ({ chipId, e, c }) => {
/* … */
},
// Scan as soon as an already-authorized reader connects, with no click.
// Without this, a return visit connects silently and then sits idle.
autoStartWhenGranted: true,
});
// Pairing: only while the browser has not been given a reader yet.
{
needsAuthorization && <button onClick={requestDevice}>Connect reader</button>;
}
// Scanning: for a reader that is connected but stopped.
{
!needsAuthorization &&
(isScanning ? (
<button onClick={stopScanning}>Stop</button>
) : (
<button onClick={startScanning}>Start scanning</button>
));
}