Skip to content
react-cards-opening

Hiding places

A hunt hides each card on a cell of a grid. pickSpot chooses one: lit, and not taken by another card. useCardSpots remembers the choice for the rest of the visit, so a card found on one tile is found on that tile again in a replay.

Pick a cell

ts
import { pickSpot } from "@react-cards-opening/core";

const levels = [0, 2, 0, 3, 1, 4]; // one number per cell, 0 is unlit
const cell = pickSpot(levels, [3]); // 1, 4 or 5: lit, and 3 is taken

Cards hide where there is something to find: an unlit cell is only used when nothing lit is free. The third argument is the random source. Pass createRng(seed).next to place cards the same way on every device.

Remember it

tsx
import { useCardSpots } from "@react-cards-opening/core";

const [spots, setSpots] = useCardSpots("deal:ada:2026:spots");
// spots["ash-phoenix"] === 142

It works like useState, with session storage behind it: the spots survive a reload and are gone when the tab closes. Pass null to keep them in memory. CardHunt does all of this for you through its sessionKey prop.

Why not decide it up front

A cell is picked when its card's turn comes, not when the deal is made. Nothing in the page's HTML or state says where an unfound card is, so there is nothing to peek at in the inspector.

Last updated . Read this page as Markdown.