defineComponent is the primary building block of every Solar component. You pass it a configuration object that declares the component’s name, its props schema, and a render function. Solar validates the configuration at definition time and returns a ComponentFn that validates props on every call — giving both runtime safety and a machine-readable contract the registry exposes to AI agents and platform tools.
Signature
Parameters
The full component configuration.
The PascalCase display name for the component. Solar uses this in error messages, the component registry, and the
displayName property of the returned function. Must be unique across your application.A prop schema object. Each key is a prop name; each value is a schema descriptor that describes the prop’s type, whether it’s required, and any constraints. See the Prop schema descriptor section below. If omitted, the component accepts no declared props.
A function that receives the resolved props object (with defaults applied) and returns a vnode. Build your vnode tree using
createElement or h() inside this function.Prop schema descriptor
Each value in theprops object is a schema descriptor with the following fields:
| Field | Type | Description |
|---|---|---|
type | string | Required. The expected type of the prop. One of: 'string', 'number', 'boolean', 'function', 'object', 'array', 'any', 'slot'. |
required | boolean | If true, Solar throws a ContractError when this prop is missing or null at call time. |
default | any | Fallback value applied when the prop is not provided. Ignored if the prop is present. |
enum | array | Restricts the prop to a list of allowed string values. Solar throws a ContractError if the value is not in the list. |
accepts | string | Only valid when type is 'slot'. The displayName of the component whose vnode the slot accepts. Passing a vnode from any other component throws a ContractError. |
Return value
defineComponent returns a ComponentFn — a plain function you call with a props object. It validates the incoming props against the schema, applies defaults, and calls render with the resolved props.
The callable component function. Invoke it with a props object to produce a vnode:
Button({ label: 'Save', onClick: handleSave }).The component name you provided in
config.name. Used by the registry, error messages, and typed slot validation.Example
Throws
| Condition | Error type |
|---|---|
config.name is missing or falsy | Error — thrown immediately at definition time |
config.render is missing | Error — thrown immediately at definition time |
A required prop is missing or null at call time | ContractError |
| A prop value has the wrong type | ContractError |
A prop value is not in the declared enum list | ContractError |
A slot prop receives a vnode from the wrong component | ContractError |
ContractError extends Error and includes a .toJSON() method that returns a structured object with component, prop, expected, received, and fix fields — designed to be parseable by an AI agent for self-correction.