Skip to main content

Schema State Hooks

The View Builder package provides React hooks for managing view schema state. These hooks enable components to access and modify the schema, validate it, and persist it to storage.

Features

  • Centralized State Management: Single source of truth for schema data
  • Schema Validation: Validate schemas against specifications
  • Persistence: Save and load schemas from storage
  • Field Management: Add, update, and remove fields
  • Type Safety: TypeScript definitions for all schema types

useSchemaState Hook

The useSchemaState hook provides access to the schema state and operations:

SchemaProvider Component

The SchemaProvider component provides the schema state context to its children:

Schema Operations

Adding a Field

Updating a Field

Removing a Field

Validating the Schema

Persisting the Schema

Loading a Schema

Advanced Usage

Custom Initial Schema

You can provide a custom initial schema to the provider:

Custom Storage Provider

You can provide a custom storage provider:

Schema History

You can implement undo/redo functionality: