Skip to content
react-wrapped

useScanGate

useScanGate decides when the scan is the whole page. A creator who has opened nothing yet sees the scan alone, with one button. When a scan has come to rest with something found, the video takes over, and it never goes back. WrappedView uses this hook when you set opening.gate. Reach for it when you build the page yourself.

A page that opens on its scan. Find the scenes and the video takes over.

Usage

tsx
import { useOpenedDrops, useScanGate, YearScan } from "@react-wrapped/scan";

// With `gate`, the scan is the page until one run has come to rest with something found.
const { gated, onRunChange } = useScanGate({ enabled: gate, found: opened.length, id: cut.seed });
// The video takes the scan's place at the top, so that is where the page should be looking.
const rootRef = useRef<HTMLDivElement>(null);
const wasGated = useRef(gated);
useLayoutEffect(() => {
  if (wasGated.current && !gated) rootRef.current?.scrollIntoView({ block: "start" });
  wasGated.current = gated;
}, [gated]);

That is from the from parts example. While gated is true it renders the scan in a box as tall as the video will be and nothing else. Afterwards it renders the player, the settings and the gallery, with the same scan under them.

Options

OptionTypeWhat it does
enabledbooleanWhether this Wrapped opens on its scan at all: someone's own year with drops in it, not an example.
foundnumberHow many drops have been found so far.
idstring | nullWhich Wrapped this is, such as its seed, so another year opened in the same place starts at its own scan.
beat?numberMilliseconds the finished scan stays up before the video takes over. 900 unless you say.

What it returns

KeyTypeWhat it is
gatedbooleanTrue while the scan is the page. Render the scan alone, and pass this on as its gate.
onRunChange(running: boolean) => voidHand it to YearScan. It is how the hook knows a scan started or came to rest.

The rules it keeps

  • The page stays the scan's while the scan it started is still going. The first find must not pull the layout out from under the ones after it.
  • A scan stopped with nothing found leaves the scan as the page, ready to run again.
  • A scan run later, under the video, never takes the page back.
  • Someone who has already found something, on an earlier visit, goes straight to the video: read found from `useOpenedDrops`.

Last updated . Read this page as Markdown.