๐ŸŽฎ Beta Gamer

Chess โ€” React Native SDK

The React Native chess integration is fully native โ€” no WebView. This page is the complete API reference. For a step-by-step setup walkthrough see the React Native guide.

ChessBoard

Renders the chess board using native React Native views. By default it renders the board only โ€” you control the surrounding layout. Pass layout="default" to get the built-in full layout (player rows, clocks, AFK banner, resign/draw buttons, game-over modal).

The board manages its own socket internally. Pass connectSocket={false} to BetaGamerProvider to avoid a duplicate connection.

PropTypeDefaultDescription
layout"board-only" | "default""board-only"board-only = just the board. default = player rows, clocks, AFK banner, resign/draw buttons, game-over modal.
styleViewStyleโ€”Style applied to the outer container View.
orientation"white" | "black" | "auto""auto"Which color is at the bottom. auto uses the color assigned in game:started.
showCoordsbooleantrueShow rank (1โ€“8) and file (aโ€“h) labels around the board.
showLastMovebooleantrueHighlight the from/to squares of the last move played.
showLegalMovesbooleantrueShow dots on squares where the selected piece can legally move.
showAfkWarningbooleantrueShow the built-in AFK countdown banner. Only applies when layout="default".
gameChessGameStateโ€”Pass a useChessGame() instance to share one socket with the board. If omitted, the board creates its own socket.
onLeave() => voidโ€”Called when the player taps Leave or the exit button on the game-over modal.
import { BetaGamerProvider, ChessBoard } from '@beta-gamer/react-native';

<BetaGamerProvider token={sessionToken} connectSocket={false}>
  {/* Board only โ€” build your own layout */}
  <ChessBoard style={{ flex: 1 }} onLeave={handleLeave} />

  {/* Or full built-in layout */}
  {/* <ChessBoard layout="default" style={{ flex: 1 }} onLeave={handleLeave} /> */}
</BetaGamerProvider>

useChessGame()

The hook that powers ChessBoard internally. Use it when you need direct access to the socket or game state โ€” for a custom UI, listening to events, or building your own layout around the board.

Pass the returned instance to ChessBoard via the game prop so the board reuses your socket instead of creating a second one.

import { BetaGamerProvider, ChessBoard, useChessGame } from '@beta-gamer/react-native';

function GameUI() {
  const game = useChessGame(); // one socket โ€” shared with the board

  useEffect(() => {
    if (!game.socket) return;
    game.socket.on('game:over', ({ winner }) => { /* your logic */ });
    return () => { game.socket?.off('game:over'); };
  }, [game.socket]);

  return <ChessBoard game={game} layout="board-only" onLeave={handleLeave} />;
}

export function GameScreen({ sessionToken }) {
  return (
    <BetaGamerProvider token={sessionToken} connectSocket={false}>
      <GameUI />
    </BetaGamerProvider>
  );
}

Return value:

FieldTypeDescription
socketSocket | nullSocket.IO socket connected to /chess
roomIdstring | nullCurrent game room ID
myPlayerIdstringYour player ID assigned by the server
myColor"white" | "black"Your assigned color
fenstringCurrent board position in FEN notation
playersany[]Both players in turn order
clocks{ self: number; opponent: number }Remaining time in seconds for each player
isMyTurnbooleanWhether it is currently your turn
selectedstring | nullCurrently selected square (e.g. "e2")
legalMovesstring[]Legal destination squares for the selected piece
lastMove{ from, to } | nullThe last move played
moveHistory{ san: string }[]Full move history in algebraic notation
gameOverbooleanWhether the game has ended
gameResult{ winner, reason } | nullGame result once over
handleSquarePress(square: string) => voidCall on square tap โ€” handles selection and move emission
emitMove(from, to, promotion?) => voidEmit a move directly to the server

Custom UI (no ChessBoard)

If you don't want to use ChessBoard at all and prefer to render everything yourself, use useChessGame() directly. Keep connectSocket={true} (the default) on the provider โ€” or omit it entirely.

import { BetaGamerProvider, useChessGame } from '@beta-gamer/react-native';

function MyCustomChessUI() {
  const { chess, selected, legalMoves, isMyTurn, handleSquarePress, gameOver, gameResult } = useChessGame();

  // render your own board, clocks, player rows, etc.
  return ( /* ... */ );
}

export function GameScreen({ sessionToken }) {
  return (
    // connectSocket={true} is the default โ€” no need to pass it
    <BetaGamerProvider token={sessionToken}>
      <MyCustomChessUI />
    </BetaGamerProvider>
  );
}
Only use connectSocket={false} when using ChessBoard (or any board component) โ€” they open their own socket. Using both creates a duplicate connection.

ChessMoveHistory

Scrollable move list in algebraic notation. Works alongside ChessBoard or useChessGame().

PropTypeDefaultDescription
styleViewStyleโ€”Style for the scroll container
textStyleTextStyleโ€”Style for each move text
rowStyleViewStyleโ€”Style for each move row
Step-by-step setup โ†’ React Native guide ยท Socket events โ†’ Chess events
Beta Gamer GaaS API โ€” questions? support@beta-gamer.com