Table of Contents
Advanced Usage
Schema Composition
Compose complex schemas from smaller parts:
Conditional Content
Use unions for conditional content structures:
Core Functions
initVal(config)
Normally you do not need to use this function directly, it should be setup by the init script. Initialize Val with configuration options. Returns schema builders and configuration.
Parameters:
Your project identifier (org/repo). You need this to connect to admin.val.build. Run the CLI command npx val connect to start the setup process.
Current git branch (optional)
Current git commit SHA (optional)
Default theme for Val Studio
The relative path of the project inside the repo. Used for monorepos. Example: ./web if your NextJS project is in the web/ folder.
Returns:
{ s, c, val, config }Example:
Example
useVal(moduleVal)
Fetch content data from a Val schema definition (server-side only).
Parameters:
The module definition to fetch content for
Returns:
TExample:
Example
useValRoute(moduleVal, params)
Use this with page.val.ts modules that use the .route() method (client-side only).
Parameters:
The module definition to fetch content for
The parameters to fetch content for, used to resolve the path
Returns:
TExample:
Example
fetchVal(moduleVal)
Fetch content data from a Val module definition (server-side only).
Parameters:
The module definition to fetch content for
Returns:
Promise<T>Example:
Example
fetchValRoute(moduleVal, params)
Use this with page.val.ts modules that use the .route() method (server-side only).
Parameters:
The module definition to fetch content for
The parameters to fetch content for, used to resolve the path
Returns:
Promise<T>Example:
Example
c.define(path, schema, data)
Define content with schema validation and default data.
Parameters:
File path identifier
Schema definition
Default content data
Returns:
ValSchema<T>Example:
Example
initValRsc(config, modules, nextjs)
Normally you do not need to use this function directly, it should be setup by the init script. Initialize Val for React Server Components with Next.js integration.
Parameters:
Val configuration
Val modules definition
Next.js integration options
Returns:
{ fetchValStega, fetchValRouteStega, fetchValRouteUrl }Example:
Example
initValClient(config, modules, nextjs)
Normally you do not need to use this function directly, it should be setup by the init script. Initialize Val for Client Components with Next.js integration.
Parameters:
Val configuration
Val modules definition
Next.js integration options (optional)
Returns:
{ useVal, useValRoute, useValRouteUrl }