A highly flexible and customizable React Native library for creating and editing chess board positions (FEN strings) without enforcing game rules. Perfect for building puzzle creators, position analysis tools, or chess setup utilities.
| π Full Documentation |
BoardEditornpm install react-native-chess-board-editor
or
yarn add react-native-chess-board-editor
This library requires the following peer dependencies:
npm install react-native-gesture-handler react-native-reanimated react-native-svg
Make sure to complete the setup for react-native-gesture-handler and react-native-reanimated.
import React, { useState } from 'react';
import { View } from 'react-native';
import { BoardEditor } from 'react-native-chess-board-editor';
export default function App() {
const [fen, setFen] = useState('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
return (
<View style=>
<BoardEditor
initialFen={fen}
onFenChange={setFen}
/>
</View>
);
}
import React, { useState } from 'react';
import { View } from 'react-native';
import {
EditableBoard,
PieceBank,
FenDisplay,
TurnToggler,
CastlingRightsTogglers,
} from 'react-native-chess-board-editor';
export default function CustomEditor() {
const [fen, setFen] = useState('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
return (
<View>
<EditableBoard fen={fen} onFenChange={setFen} />
<PieceBank />
<FenDisplay fen={fen} onFenChange={setFen} editable />
<TurnToggler turn="w" onTurnChange={(turn) => {/* handle */}} />
<CastlingRightsTogglers castlingRights="KQkq" onCastlingChange={(rights) => {/* handle */}} />
</View>
);
}
| Component | Description |
|---|---|
BoardEditor |
All-in-one component combining board, bank, and controls |
EditableBoard |
Interactive chess board with drag & drop |
PieceBank |
Piece palette for adding pieces to the board |
FenDisplay |
Display and edit FEN strings |
| Component | Description |
|---|---|
TurnToggler |
Switch between white and black to move |
CastlingRightsTogglers |
Toggle castling availability (K, Q, k, q) |
EnPassantInput |
Set en passant target square |
EditorToolsPanel |
Collection of editor utility buttons |
PieceSetSelector |
Switch between different piece set styles |
FlipBoardButton |
Rotate the board 180Β° |
| Component | Description |
|---|---|
Piece |
Render individual chess pieces |
RankLabels |
Display rank labels (1-8) |
FileLabels |
Display file labels (a-h) |
Use the BoardThemeProvider to customize board appearance:
import { BoardThemeProvider } from 'react-native-chess-board-editor';
<BoardThemeProvider
theme=
>
<BoardEditor initialFen={fen} onFenChange={setFen} />
</BoardThemeProvider>
Register and use custom piece renderers:
import { registerCustomPieceSet, BoardEditor } from 'react-native-chess-board-editor';
registerCustomPieceSet('myCustomSet', {
K: (props) => <MyWhiteKing {...props} />,
Q: (props) => <MyWhiteQueen {...props} />,
// ... other pieces
});
<BoardEditor pieceSet="myCustomSet" />
All components accept standard React Native style props:
<EditableBoard
squareSize={50}
lightSquareColor="#ECECEC"
darkSquareColor="#769656"
style=
/>
For detailed API documentation, prop references, and advanced usage examples, visit:
π https://your-docs-site.com
The library exports utility functions for FEN manipulation:
import { parseFen, updateFenField, validateFen } from 'react-native-chess-board-editor';
const fenParts = parseFen('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
const newFen = updateFenField(fen, 'turn', 'b');
const isValid = validateFen(fen);
Filter pieces shown in the PieceBank:
import { PieceBank, whitePiecesOnly } from 'react-native-chess-board-editor';
<PieceBank pieceFilter={whitePiecesOnly} />
The board can be flipped to show from blackβs perspective:
<EditableBoard fen={fen} onFenChange={setFen} flipped />
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)This project is licensed under the MIT License - see the LICENSE file for details.
Made with β€οΈ for the React Native community