dioxus/packages/recoil/examples/selectorlist.rs

36 lines
847 B
Rust
Raw Normal View History

2021-05-26 05:40:30 +00:00
use std::collections::HashMap;
use dioxus_core::prelude::*;
use recoil::*;
const A_ITEMS: AtomFamily<i32, i32> = |_| HashMap::new();
const B_ITEMS: AtomFamily<i32, i32> = |_| HashMap::new();
const C_SELECTOR: SelectorFamily<i32, i32> = |api, key| {
let a = api.get(&A_ITEMS.select(&key));
let b = api.get(&B_ITEMS.select(&key));
a + b
};
const D_SELECTOR: SelectorFamilyBorrowed<i32, i32> = |api, key| -> &i32 {
let a = api.get(&A_ITEMS.select(&key));
a
};
static App: FC<()> = |ctx, _| {
2021-05-26 15:22:44 +00:00
use_init_recoil_root(ctx);
2021-05-26 05:40:30 +00:00
2021-05-26 15:22:44 +00:00
let title = use_recoil_value(ctx, &C_SELECTOR);
2021-05-26 05:40:30 +00:00
let title = "";
rsx! { in ctx,
div {
"{title}"
// button { onclick: {next_light}, "Next light" }
}
}
};
fn main() {
wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
}