with!() { /* proc-macro */ }Expand description
The with! macro for cloning state handles into closures.
State
ยงExamples
Single state:
โ
let count = state!(cx, || 0);
let increment = with!(count => move || count.update(|n| *n += 1));Multiple states:
โ
let count = state!(cx, || 0);
let name = state!(cx, || String::new());
let handler = with!(count, name => move || {
count.update(|n| *n += 1);
name.set("updated".to_string());
});The above expands to:
โ
let handler = {
let count = count.clone();
let name = name.clone();
move || {
count.update(|n| *n += 1);
name.set("updated".to_string());
}
};