Skip to main content

view_fn

Function view_fn 

Source
pub fn view_fn<F, V>(f: F) -> FnView<F>
where F: Fn() -> V + 'static, V: View,
Expand description

Wraps a closure as a view. Whatever state the closure reads is tracked, so this is the simplest way to make a region of the UI depend on state:

use ravenrs_reactive::State;
use ravenrs_widgets::{Text, view_fn};

let logged_in = State::new(false);
let l = logged_in.clone();
let greeting = view_fn(move || Text::new(if l.get() { "Welcome back" } else { "Sign in" }));