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

@khazh/tic-tac-toe-react

v1.0.3

Published

A customizable Tic Tac Toe game component for React with AI opponent, configurable board size, and win conditions

Readme

Tic Tac Toe React Component

A customizable Tic Tac Toe game component for React with AI opponent, configurable board size, and flexible win conditions.

Features

  • 🎮 Customizable Board Size: Play on boards from 3x3 to any size
  • 🎯 Flexible Win Conditions: Configure how many in a row to win
  • 🤖 AI Opponent: Built-in AI with smart move selection
  • 🎨 Customizable Styling: Pass custom CSS classes and styles
  • 📱 Responsive Design: Adapts to different screen sizes
  • 🏆 Score Tracking: Keep track of wins, losses, and draws
  • 🔄 Game History: Undo/redo functionality
  • 📦 TypeScript Support: Full type definitions included

Installation

yarn add @khanhpham/tic-tac-toe-react

or

npm install @khanhpham/tic-tac-toe-react

Quick Start

import React from 'react';
import { TicTacToe } from '@khanhpham/tic-tac-toe-react';

function App() {
  return (
    <div>
      <h1>My Tic Tac Toe Game</h1>
      <TicTacToe />
    </div>
  );
}

Basic Usage

Default Game (3x3 board, 3 in a row to win)

import { TicTacToe } from '@khanhpham/tic-tac-toe-react';

<TicTacToe />

Custom Board Size and Win Condition

<TicTacToe 
  initialBoardSize={5} 
  initialWinLength={4} 
/>

Custom Styling

<TicTacToe 
  className="my-custom-game"
  style={{ 
    backgroundColor: '#f0f0f0',
    borderRadius: '10px',
    padding: '20px'
  }}
/>

Handle Winner Events

<TicTacToe 
  onWinner={() => {
    console.log('Player X won!');
    // Add your custom logic here
  }}
/>

Hide Configuration Controls

<TicTacToe 
  showConfigControls={false}
/>

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | initialBoardSize | number | 10 | Initial size of the game board | | initialWinLength | number | 4 | Number of marks in a row needed to win | | showConfigControls | boolean | true | Whether to show configuration controls | | className | string | "" | Additional CSS class name | | style | React.CSSProperties | {} | Additional inline styles | | onWinner | () => void | () => {} | Callback when a player wins |

Advanced Usage

Using Individual Hooks

import { 
  useGameState, 
  useScore, 
  useAI, 
  useGameMode,
  useBoardSize,
  useWinLength 
} from '@khanhpham/tic-tac-toe-react';

function CustomGame() {
  const { boardSize } = useBoardSize(5);
  const { winLength } = useWinLength(5, 4);
  const { gameMode } = useGameMode();
  const { gameState, makeMove, resetGame } = useGameState(boardSize, winLength);
  const { updateScore, getTotalGames } = useScore();

  // Your custom game logic here
  return (
    <div>
      {/* Custom game UI */}
    </div>
  );
}

Using Types

import type { 
  Player, 
  GameMode, 
  Board, 
  GameConfig, 
  GameState, 
  Score 
} from '@khanhpham/tic-tac-toe-react';

// Use types in your custom components

Game Modes

  • Player vs Player: Two human players take turns
  • Player vs AI: Human player (X) vs AI opponent (O)

AI Features

The AI opponent uses a smart algorithm to:

  • Block winning moves
  • Create winning opportunities
  • Play strategically based on board position
  • Adapt to different board sizes and win conditions

Styling

The component is fully customizable through:

  • CSS classes via className prop
  • Inline styles via style prop
  • Responsive design that adapts to board size

Browser Support

  • React 16.8+ (for hooks support)
  • Modern browsers with ES2020 support
  • TypeScript 4.0+

Development

# Install dependencies
yarn install

# Start development server
yarn dev

# Build for production
yarn build

# Build library for npm
yarn build:lib

# Lint code
yarn lint

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.