React Guide
This guide covers React development with the Xams framework, including the useAuthRequest hook and component patterns.
React components are built using Mantine v7 and React component examples can be found here
useAuthRequest Hook
The useAuthRequest
hook is the primary interface for making API requests to the Xams backend. It provides a comprehensive set of methods for CRUD operations, permissions, metadata, and custom actions.
Basic Usage
Hook Methods Reference
Core CRUD Operations
create(tableName, fields, parameters?) Creates a new record in the specified table.
read(readRequest) Queries records with advanced filtering, sorting, and joining capabilities.
update(tableName, fields, parameters?) Updates an existing record. The fields object must include the primary key.
delete(tableName, id, parameters?) Deletes a record by its primary key.
upsert(tableName, fields, parameters?) Creates or updates a record based on unique constraints.
Bulk Operations
bulkCreate(entities, parameters?) Creates multiple records in a single transaction.
bulkUpdate(entities, parameters?) Updates multiple records in a single transaction.
bulkDelete(entities, parameters?) Deletes multiple records in a single transaction.
bulkUpsert(entities, parameters?) Performs bulk upsert operations.
bulk(bulkRequest) Executes a complex bulk operation with mixed CRUD actions.
Custom Actions
action(actionName, parameters?, fileName?) Executes a custom server action. Can return JSON data or trigger file downloads.
File Operations
file(formData) Uploads files to the server.
Metadata Operations
metadata(tableName) Retrieves metadata for a table including field definitions, attributes, and relationships.
tables(tag?) Retrieves a list of available tables, optionally filtered by tag.
Permission Operations
hasAllPermissions(permissions) Checks if the current user has all specified permissions.
hasAnyPermissions(permissions) Checks if the current user has any of the specified permissions.
User Information
whoAmI() Retrieves information about the current authenticated user.
Advanced Query Examples
Complex Filtering
Joins and Related Data
Pagination
Error Handling Patterns
Basic Error Handling
Try-Catch with useAuthRequest
Permission-Based UI
Best Practices
1. Always Check Response Success
2. Use TypeScript Generics
3. Handle Loading States
4. Optimize with useMemo
The useAuthRequest
hook already uses useMemo
internally, but be mindful of dependencies:
5. Batch Permission Checks
This comprehensive reference covers all aspects of the useAuthRequest
hook and provides practical examples for common use cases in Xams applications.