Skip to main content

render

Function render 

Source
pub async fn render<F>(initializer: F) -> Result<()>
where F: Fn() -> Element + 'static,
Expand description

Renders a component-based TUI application with hooks support

This function sets up a hook context and manages the component lifecycle including state persistence between renders.

§Arguments

  • app_fn - A closure that returns an Element (supports both components and RSX)

§Example

use reratui::prelude::*;

#[component]
fn Counter() -> Element {
    let (count, set_count) = use_state(|| 0);
    rsx! { <Text text={format!("Count: {}", count)} /> }
}

// Direct component
render(|| Counter()).await.unwrap();

// Or with RSX
render(|| {
    rsx! { <Counter /> }
}).await.unwrap();