npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-tetris2

v0.1.3

Published

Classic Tetris game as a reusable React 18+ component, fully typed with TypeScript and controllable via ref.

Readme

react‑tetris2

npm version bundle size MIT License

react‑tetris2 – Plug-and-play <Tetris2/> component for React 18+, built with TypeScript.

🎮 Live Demo – Try Tetris2 here ⬅️

✨ Features

  • Fully typed API – Strictly typed props and methods with TypeScript 5.
  • Modular architecture – Use as a component with optional ref control.
  • Keyboard controls – Playable entirely via keyboard input.
  • Imperative API – Call start(), restart() via ref for external control.

🚀 Installation

# npm
npm i react-tetris2
# pnpm
pnpm add react-tetris2

Note: react and react-dom are required as peer dependencies.
Make sure your project includes them (React 18+ supported).

🤖 Quick start

Use the component right after installation — no additional setup required.

Example: main.tsx (Vite)

💡 Make sure to comment out global CSS imports (e.g., index.css) to avoid style conflicts.

// src/main.tsx
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import Tetris2 from 'react-tetris2';
// import './index.css'; // optional: comment this out to avoid conflicts

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <Tetris2 />
  </StrictMode>
);

🔧 Customized usage

For advanced control and customization, use a ref and props:

// src/main.tsx
import React, { StrictMode, useRef } from 'react';
import { createRoot } from 'react-dom/client';
import Tetris2, { Tetris2Handle } from 'react-tetris2';

function App() {
  const game = useRef<Tetris2Handle>(null);

  return (
    <>
      <Tetris2
        ref={game}
        credits={3}
        manageCredits={true}
        showModals={true}
        soundEnabled={true}
        showControlsLegend={true}
        onGameOver={() => alert('Game Over!')}
        onScoreChange={(score) => console.log('Score:', score)}
        onLevelChange={(level) => console.log('Level:', level)}
      />
      <div style={{ marginTop: '1rem' }}>
        <button onClick={() => game.current?.start()}>Start</button>
        <button onClick={() => game.current?.restart()}>Restart</button>
      </div>
    </>
  );
}

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <App />
  </StrictMode>
);

📝 API

Props

| Prop | Type | Default | Description | | -------------------- | ------------------------- | ------- | ------------------------------------- | | credits | number | — | Number of available game credits | | manageCredits | boolean | false | Enable credit-based game start | | showModals | boolean | true | Show start/pause/game over modals | | soundEnabled | boolean | true | Enable background music | | showControlsLegend | boolean | true | Show control instructions below board | | onGameOver | () => void | — | Callback when the player loses | | onScoreChange | (score: number) => void | — | Callback when score updates | | onLevelChange | (level: number) => void | — | Callback when level updates |

Imperative API

| Method | Description | | ----------- | ------------------------ | | start() | Start or resume the game | | restart() | Restart the game |

Consult index.d.ts for the full API surface.

🎵 Audio

This component includes background music: a string-quartet arrangement of
“Korobeiniki (Tetris Theme)” by Gregor Quendel, licensed under the Pixabay License.

🧪 Contributing

We welcome contributions! Follow the steps below to get started:

  1. Clone the repository and install dependencies

    git clone https://github.com/Ingenarte/react-tetris2.git
    cd react-tetris2
    npm install
  2. Start the local playground

    This will launch a development environment with hot reload:

    npm dev
  3. Run the full test suite (unit + E2E)

    Make sure your changes don't break anything:

    npm test       # or: npm fulltest
  4. Create a feature branch

    Avoid working directly on master:

    git checkout -b your-feature-name
  5. Commit and push your changes

    Follow Conventional Commits if possible:

    git commit -m "feat: add new animation for line clear"
    git push origin your-feature-name
  6. Open a Pull Request

    Submit your PR against the master branch at:
    https://github.com/Ingenarte/react-tetris2/pulls


💡 Tip: You can also run Storybook locally with:

npm run storybook

🛠️ Internal tools like lint, typecheck, and build are available via npm scripts.
Always run npm fulltest before pushing.

🛣️ Roadmap (posible)

  • [ ] Enhanced accessibility (ARIA roles, focus trapping, high-contrast mode)
  • [ ] Multiplayer LAN
  • [ ] AI opponent
  • [ ] Replay export / import

📜 License

MIT – see LICENSE for details.
Original work © 2015 Matthew Brandly.
Additions & refactor © 2025 INGENARTE.
Audio © 2024 Gregor Quendel.

TETRIS® is a registered trademark of Tetris Holding LLC. This project is not affiliated with or endorsed by Tetris Holding LLC, Nintendo, or The Tetris Company.