useQuery
hook provides a React-friendly way to query game state from your
World Engine shard. It handles loading states, errors, and automatic re-execution when dependencies change.
Prerequisites: Make sure you understand the basics by reading the Query
guide first. This guide focuses on React-specific usage patterns.
Basic Usage
Basic Usage
Query States
The hook returns a state object with four possible statuses:idle
- Query is disabled via thedisabled
proploading
- Query is in progresssuccess
- Query completed successfully,data
contains resultserror
- Query failed,error
contains the error details
Conditional Queries
Use thedisabled
prop to conditionally execute queries:
Conditional Queries
Type Safety with Schema
Combine with schema validation for full type safety:Type Safety with Schema
Best Practices
- Always handle all status states (
idle
,loading
,success
,error
) explicitly - Combine with schema validation for runtime type safety
- Create schema outside of the component to avoid re-creating it on every render