Skip to main content

component

Function component 

Source
pub fn component(
    build: impl Fn(&BuildContext<'_>) -> Box<dyn Widget> + 'static,
) -> Component
Expand description

A component made of a function: component(|cx| …). The closure is called whenever the tree is rebuilt, and may call hooks.

use frus_widgets::{component, text};

let clock = component(|cx| {
    let ticks = cx.use_state(|| 0);
    Box::new(text(format!("{} ticks", ticks.get())))
});