novdom/state/component

Functions

pub fn if1(
  parameter: List(Parameter),
  state state: State(a),
  when should_show: fn(a) -> Bool,
  then comp: Component,
) -> Component

Shows or hides the given component based on the result of the should_show function.

This will wrap the given components in a parent component. The given Parameter will be apllied to the parent.

pub fn ternary1(
  parameter: List(Parameter),
  state state: State(a),
  when should_show: fn(a) -> Bool,
  then comp1: Component,
  otherwiese comp2: Component,
) -> Component

Switches between the two given components based on the result of the should_show function.

This will wrap the given components in a parent component to be able to switch between them. The given Parameter will be apllied to the parent.

pub fn utilize(
  parameter: List(Parameter),
  state: State(a),
  do: fn(a) -> Component,
) -> Component

Rerenders the component using the do function on every state change.

This will wrap the created component in a parent component to be able to replace it. The given Parameter will be apllied to the parent.

Attention: Only use this function as a last resort.
Prefer if(..) or ternary(..). To display every item of a list, use novdom/state/list.map(..).
All named alternatives are way more performant.

Search Document