{"id":18605538,"url":"https://github.com/bboydflo/use-tetris","last_synced_at":"2025-05-17T09:42:19.237Z","repository":{"id":57388501,"uuid":"377144748","full_name":"bboydflo/use-tetris","owner":"bboydflo","description":"tetris game implemented as a react/preact hook","archived":false,"fork":false,"pushed_at":"2021-06-15T16:28:27.000Z","size":478,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-27T05:21:06.489Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bboydflo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-15T11:51:18.000Z","updated_at":"2023-03-04T06:10:11.000Z","dependencies_parsed_at":"2022-09-19T01:31:29.060Z","dependency_job_id":null,"html_url":"https://github.com/bboydflo/use-tetris","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bboydflo%2Fuse-tetris","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bboydflo%2Fuse-tetris/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bboydflo%2Fuse-tetris/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bboydflo%2Fuse-tetris/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bboydflo","download_url":"https://codeload.github.com/bboydflo/use-tetris/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239394719,"owners_count":19631121,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-07T02:22:01.551Z","updated_at":"2025-02-18T02:14:48.537Z","avatar_url":"https://github.com/bboydflo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tetris game logic implemented as a custom hook\n\nThis is a fun project with the sole purpose to learn new things. It is a work in progress. Currently there are some things missing:\n\n1.  add levels\n2.  increase speed (gravitation) for each level\n3.  simplify current hook using `useReducer` for the game logic\n\nI've extracted this from another project which you can try here [https://florin-cosmin-tetris.netlify.app/](https://florin-cosmin-tetris.netlify.app/)\n\n## How to use it\n\n```bash\nnpm i use-tetris@latest -E\n```\n\nThen in your JavaScript/TypeScript code:\n\n```tsx\nimport React from 'react'\nimport { render } from 'react-dom'\nimport { useTetris } from 'use-tetris'\n\n// copied from: https://usehooks-typescript.com/react-hook/use-event-listener\nimport useEventListener from './use-event-listener'\n\nconst TetrisApp: React.FC = () =\u003e {\n    const {\n        tetrisState,\n        handleKey\n    } = useTetris()\n\n    // listen for keydown events\n    useEventListener('keydown', function(event) {\n        const keycode = (event as KeyboardEvent).keyCode as keyof typeof browserKeyCodeMap\n        const key = browserKeyCodeMap[keycode]\n\n        handleKey(key)\n    })\n\n    const { score, grid, piece, nextPiece, gameState } = tetrisState\n\n    return (\n        ...\n    )\n}\n\nrender(\u003cTetrisApp /\u003e, document.querySelector('#root'))\n```\n\nThis project was bootstrapped using [tsdx.io](https://tsdx.io)\n\nIf you want to get in contact with me you can always DM me on [twitter](https://mobile.twitter.com/CosminOnciu)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbboydflo%2Fuse-tetris","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbboydflo%2Fuse-tetris","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbboydflo%2Fuse-tetris/lists"}