Tic-tac-toe — React Native integration guide
The TictactoeBoard component is fully native — no WebView. It manages its own socket, handles mark placement, winning line detection, AFK, and game-over automatically.
1
Install the SDK
npm install @beta-gamer/react-nativeNo react-native-webview needed — the board is fully native.
2
Create a session on your backend
⚠️ Never call the Beta Gamer API directly from your app. Your API key would be bundled into the binary and is trivially extractable from any APK or IPA.
📄 server/routes/game.js
app.post('/api/game/start', async (req, res) => {
const { userId, userName, game, matchType } = req.body;
const resp = await fetch('https://api.beta-gamer.com/v1/sessions', {
method: 'POST',
headers: { 'Authorization': 'Bearer bg_live_xxxx', 'Content-Type': 'application/json' },
body: JSON.stringify({
game, matchType, players: [{ id: userId, displayName: userName }],
}),
});
const { sessionToken, sessionId } = await resp.json();
res.json({ sessionToken, sessionId });
});3
Create a lobby screen
📄 src/screens/TictactoeLobbyScreen.tsx
import { useState } from 'react';
import { View, Button, ActivityIndicator } from 'react-native';
import { useNavigation } from '@react-navigation/native';
export function TictactoeLobbyScreen() {
const navigation = useNavigation<any>();
const [loading, setLoading] = useState(false);
const startGame = async (matchType: 'matchmaking' | 'bot') => {
setLoading(true);
const res = await fetch('https://your-api.com/api/game/start', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ game: 'tictactoe', matchType }),
});
const { sessionToken } = await res.json();
navigation.navigate('TictactoeGame', { sessionToken });
};
if (loading) return <ActivityIndicator />;
return (
<View>
<Button title="Find opponent" onPress={() => startGame('matchmaking')} />
<Button title="vs Bot" onPress={() => startGame('bot')} />
</View>
);
}4
Create the game screen
📄 src/screens/TictactoeGameScreen.tsx
import { View, StyleSheet } from 'react-native';
import { useRoute, useNavigation } from '@react-navigation/native';
import { BetaGamerProvider, TictactoeBoard } from '@beta-gamer/react-native';
export function TictactoeGameScreen() {
const { sessionToken } = useRoute<any>().params;
const navigation = useNavigation();
return (
<BetaGamerProvider
token={sessionToken}
serverUrl="https://api.beta-gamer.com"
connectSocket={false}
>
<View style={styles.screen}>
<TictactoeBoard
style={styles.board}
onLeave={() => navigation.goBack()}
/>
</View>
</BetaGamerProvider>
);
}
const styles = StyleSheet.create({
screen: { flex: 1, backgroundColor: '#0a0a0f' },
board: { flex: 1 },
});TictactoeBoard props
| Prop | Type | Description |
|---|---|---|
| style | ViewStyle | Style applied to the outer container |
| showAfkWarning | boolean | Show built-in AFK countdown banner (default true) |
| onLeave | () => void | Called when player taps Leave or Play again after game over |
Full event payload reference → Tic-tac-toe socket events
Beta Gamer GaaS API — questions? support@beta-gamer.com