pream

Types

typed component record — wraps a props-to-vnode render function so it can be named, composed, and passed around explicitly

pub type Component(p) {
  Component(render: fn(p) -> vnode.VNode)
}

Constructors

https://npmx.dev/package-docs/preact/v/10.29.2#class-ComponentChildren

pub type PreactComponent

Values

pub fn component(render: fn(p) -> vnode.VNode) -> Component(p)

construct a component from a render function

pub fn memo(comp: Component(p)) -> Component(p)

Wraps a Component so it only re-renders when its props change (shallow equality). In a signals-first app, this skips the VNode build when a parent re-renders but props haven’t changed.

pub fn memo_custom(
  comp: Component(p),
  compare: fn(p, p) -> Bool,
) -> Component(p)

Like memo but with a custom comparison function for props.

pub fn render_component(
  comp: Component(p),
  props: p,
) -> vnode.VNode

render a component with the given props

pub fn to_preact(from node: vnode.VNode) -> PreactComponent

https://npmx.dev/package-docs/preact/v/10.29.2#function-h converts a vnode tree into a preact ComponentChildren value, ready to pass to preact’s render()

pub fn to_preact_component(
  comp: Component(p),
  props: p,
) -> PreactComponent

render a component and convert directly to a preact component, ready for render()

pub fn unwrap(
  render component: fn(p) -> Result(vnode.VNode, b),
  with props: p,
) -> vnode.VNode

unwraps a Result-returning render function. an Error is silently coerced into an empty vnode — useful when a component is allowed to fail without taking down the whole tree

pub fn unwrap_option(
  render component: fn(p) -> option.Option(vnode.VNode),
  with props: p,
) -> vnode.VNode

unwraps an Option-returning render function. None is silently coerced into an empty vnode

Search Document