LogoRobo.js
Packages@robojs/sync

useSyncCall()

Function: useSyncCall()

function useSyncCall(key): SyncCallFunction

Hook 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

ParameterType
key(null | string)[]

Returns

SyncCallFunction

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!')
}

On this page