Skip to main content

with_environment

Function with_environment 

Source
pub fn with_environment<T, P>(
    value: T,
    content: impl FnOnce() -> P + 'static,
) -> impl Piece
where T: Clone + 'static, P: Piece,
Expand description

Provide an ambient value T to content and its entire descendant subtree (the SwiftUI @Environment/.environment(_) analog, layered over day-reactive’s scope context). content, and any piece built within it, reads it back with environment. A thin, non-reactive wrapper: T is a snapshot captured here; for a value that must react, provide a Signal<T> (or a Memo<T>) and read it reactively inside the subtree.

ⓘ
#[derive(Clone)] struct Theme { accent: Color }
with_environment(Theme { accent: BLUE }, || my_screen())
// deep inside my_screen():  let accent = environment::<Theme>().unwrap().accent;
Day API ↩ Guides· daybrite.dev