{"id":31216680,"url":"https://github.com/cassler/use-minesweeper","last_synced_at":"2026-04-15T14:02:23.407Z","repository":{"id":143736988,"uuid":"456536386","full_name":"cassler/use-minesweeper","owner":"cassler","description":"Basic implementation of Minesweeper as a React hook. ","archived":false,"fork":false,"pushed_at":"2022-02-09T02:31:04.000Z","size":145,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-20T04:43:09.571Z","etag":null,"topics":["games","minesweeper","postcss","react","react-hooks","tailwind","typescript","vite"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@cassler/use-minesweeper","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cassler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-07T14:19:12.000Z","updated_at":"2023-03-04T04:13:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"e8f641cd-7ee0-4a70-872d-0e493f3f5bed","html_url":"https://github.com/cassler/use-minesweeper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cassler/use-minesweeper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cassler%2Fuse-minesweeper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cassler%2Fuse-minesweeper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cassler%2Fuse-minesweeper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cassler%2Fuse-minesweeper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cassler","download_url":"https://codeload.github.com/cassler/use-minesweeper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cassler%2Fuse-minesweeper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31844329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T13:28:40.153Z","status":"ssl_error","status_checked_at":"2026-04-15T13:28:29.396Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["games","minesweeper","postcss","react","react-hooks","tailwind","typescript","vite"],"created_at":"2025-09-21T12:50:58.235Z","updated_at":"2026-04-15T14:02:23.392Z","avatar_url":"https://github.com/cassler.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Minesweeper React\n\n## Using in a project\n\n`yarn install @cassler/use-minesweeper`\n\n### MineSweeper React component\n\nImport the full component to use directly.\n\n```jsx\nimport { MineSweeper } from '@cassler/use-minesweeper';\nimport '/node_modules/@cassler/use-minesweeper/dist/style.css';\n```\n\n| Argument | Type | Default | Required | Description |\n| -------- | ----- | ----- | ------- | --------- |\n| `size`      | `number` | 12 | false | Dimensions of gameboard along each axis in absolute units. |\n| `difficulty` | `number` | 0.25 | false | Liklihood of a bomb being on any given square. Value between 0 and 1 |\n\n### useMinesweeper Hook\n\nOr just the hook to compose your own version:\n\n```jsx\nimport { useMineSweeper, BoardContext } from '@cassler/use-minesweeper'\n```\n\nThis provides most of what you need as an object. Below is an example implementation.\n\n```tsx\nexport interface Props { size: number, difficulty: number }\nexport function MyApp({ size = 12, difficulty = 0.25 }:Props) {\n  const { ctx, getGridStyle, isItemOpen, selectItem } = useMineSweeper(size, difficulty);\n  return (\n    \u003cBoardContext.Provider value={ctx}\u003e\n      \u003cdiv style={getGridStyle(size)}\u003e\n        {ctx.board.map((item, idx) =\u003e (\n          \u003cbutton type=\"button\" onClick={() =\u003e selectItem(idx)}\u003e\n            {isItemOpen(idx) ? `x${item.xAxis},y${item.yAxis}` : '?'}\n          \u003c/button\u003e\n        ))}\n      \u003c/div\u003e\n    \u003c/BoardContext.Provider\u003e\n  );\n}\n```\n\n`useMinsweeper` provides the following for composition. The values for `board`, `flippedItems` and\n`selectItem` are included as a single `ctx` object for ease-of-use. You can destruture these further\nif you want to use something other than `React.Context`.\n\n| key  | type | description                 |\n| ---- | ---- | --------------------------- |\n| `ctx.board` | `object[]` | All items on the board in an array, see types for details |\n| `ctx.flippedItems` | `number[]` | All currently flipped items by absolute index. |\n| `ctx.selectItem` | `(idx:number) =\u003e void` | Update state to flip selected index |\n| `getGridStyle` | `(size:number) =\u003e CSSProperties` | Provide CSS grid styles to apply to board container. |\n| `handleNewGame` | `() =\u003e void` | Resets the game state and generates a new board. |\n| `setSize` | `(size:number) =\u003e void` | Build a new board from the given axis length |\n| `setDifficulty` | `(diff:number) =\u003e void` | Provide a value between 0 and 1 to build a new board with the given difficulty factor. |\n\n\n## Development\n\n`yarn \u0026 yarn dev` To install dependencies and launch a dev server on Vite.\n\n`yarn build` Will transpile ES and UMD flavors of modules - both are available for consumption. Notably, [UMD modules](https://github.com/umdjs/umd) which are capable of working everywhere, be it in the client, on the server or elsewhere. This includes compatability with `require` and `import` syntaxes with special-casing to handle CommonJS compatability.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcassler%2Fuse-minesweeper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcassler%2Fuse-minesweeper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcassler%2Fuse-minesweeper/lists"}