React Integration
Games.fun provides a React SDK with hooks and components for easy integration. This guide shows how to use the React SDK in your game.
Installation
npm install @games-fun/react @games-fun/sdkProvider Setup
Wrap your app with the Games.fun provider:
import { GamesFunProvider } from '@games-fun/react';
function App() {
return (
<GamesFunProvider
options={{
debug: true,
gameServerUrl: "your-validation-endpoint"
}}
onInitialized={(connection) => {
console.log('SDK initialized:', connection);
}}
onError={(error) => {
console.error('SDK error:', error);
}}
>
<Game />
</GamesFunProvider>
);
}Game Context
Create a game context to manage state:
Components
Authentication Component
Shop Component
Inventory Component
Hooks
useGamesFun
Access SDK connection and actions:
useGamesFunActions
Register and use game actions:
Error Handling
Handle common scenarios:
Development Mode
Enable dev mode for testing:
Best Practices
State Management
Use context for game state
Handle loading states
Show error messages
Keep UI responsive
Authentication
Check auth before actions
Handle token expiry
Show auth status
Clear invalid tokens
Error Handling
Use error boundaries
Show helpful messages
Provide retry options
Log errors properly
Development
Use dev mode locally
Test error cases
Mock responses
Check console logs
Next Steps
Development Guide - Testing and deployment
Last updated