Packages@robojs/sync
useSyncCall()
Function: useSyncCall()
function useSyncCall(key): SyncCallFunctionHook for making RPC calls to server-side sync handlers.
Use this for server-authoritative operations where the server should validate and process the action, rather than direct state updates.
Parameters
| Parameter | Type |
|---|---|
key | (null | string)[] |
Returns
Examples
// Basic usage
const call = useSyncCall(['game', roomId])
const handleMove = async (x: number, y: number) => {
const result = await call('move', { x, y })
if (!result.success) {
console.log('Move rejected:', result.error)
}
}// With typed result
interface CollectResult {
points: number
}
const result = await call<{ coinId: string }, CollectResult>('collectCoin', { coinId })
if (result.success) {
console.log('Collected', result.result?.points, 'points!')
}