Skip to main content

use_sheet

Function use_sheet 

Source
pub fn use_sheet(
    factory: ModelFactory,
    schema_key: String,
    on_outcome: EventHandler<SheetEvent>,
) -> Result<SheetHandle, Rc<BuildError>>
Expand description

Initializes one owner per mounted hook, including cached construction failure.

Later factory/key prop changes do not replace the owner; call SheetHandle::replace.

§Errors

Returns independently owned construction diagnostics without a partial model.

  • Complexity: Factory and publication cost once; O(1) on subsequent renders.

§Examples

use adam_web_ui::{binding::*, build_sheet};
use dioxus::prelude::*;
use std::rc::Rc;
fn app() -> Element {
    let factory: ModelFactory = Rc::new(||
        build_sheet("sheet s { cell x: i32 = 1; }", "s.adm2"));
    match use_sheet(factory, "s/v1".into(), EventHandler::new(|_| {})) {
        Ok(sheet) => rsx! { EditNumber { bind: sheet.cell("x") } },
        Err(error) => rsx! { pre { "{error:?}" } },
    }
}