dioxus/packages/recoil/examples/selectorlist.rs

36 lines
830 B
Rust
Raw Normal View History

2021-05-26 05:40:30 +00:00
use std::collections::HashMap;
use dioxus_core::prelude::*;
use recoil::*;
2021-05-31 22:55:56 +00:00
const A_ITEMS: AtomHashMap<i32, i32> = |_| HashMap::new();
const B_ITEMS: AtomHashMap<i32, i32> = |_| HashMap::new();
2021-05-26 05:40:30 +00:00
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-27 21:57:59 +00:00
use_init_recoil_root(ctx, |_| {});
let title = use_read(ctx, &C_SELECTOR);
2021-05-26 05:40:30 +00:00
rsx! { in ctx,
div {
"{title}"
// button { onclick: {next_light}, "Next light" }
}
}
};
fn main() {
wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
}