dioxus/packages/atoms/_examples/selectorlist.rs

36 lines
823 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
};
2021-06-26 01:15:33 +00:00
static App: FC<()> = |cx| {
use_init_recoil_root(cx, |_| {});
2021-05-27 21:57:59 +00:00
2021-06-26 01:15:33 +00:00
let title = use_read(cx, &C_SELECTOR);
2021-05-26 05:40:30 +00:00
2021-06-26 01:15:33 +00:00
rsx! { in cx,
2021-05-26 05:40:30 +00:00
div {
"{title}"
// button { onclick: {next_light}, "Next light" }
}
}
};
fn main() {
wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
}