# zerolith/element

Import from `zerolith/element`. Generated from the source; every signature below is what the published types declare.

## Functions

### define

```ts
function define<Props extends readonly string[]>(name: string, options: ElementOptions<Props>): void
```

Registers a custom element for the view. Declared props are observed as
attributes and exposed as properties, both feeding the same signals, and
values assigned before the element was upgraded are kept. The content is
rendered when the element connects, hydrated when it already holds
server-rendered markup, and disposed when it disconnects. The view runs
inside the root's owner, so the effects and `onDispose` cleanups it
registers end when the element disconnects. Without a
`customElements` registry, as on the server, nothing is registered.
Defining a name twice is a no-op, so modules can re-run under hot
replacement.

Source: `packages/zerolith/src/element.ts:51`

## Interfaces

### ElementOptions

```ts
interface ElementOptions<Props extends readonly string[]>
```

Options for `define`.

- `props: Props`: The attribute and property names the element exposes. An attribute arrives as a string or undefined; a property keeps its value.
- `view: (props: ElementProps<Props>, host: HTMLElement) => unknown`: Renders the element's content from the prop signals; `host` is the element, for events and measurements.

Source: `packages/zerolith/src/element.ts:14`

## Types

### ElementProps

```ts
type ElementProps<Props extends readonly string[]> = { readonly [K in Props[number]]: ReadableSignal<unknown> }
```

The signals an element's view receives, one per declared prop.

Source: `packages/zerolith/src/element.ts:11`

