mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-23 04:33:06 +00:00
wip: usecallback
This commit is contained in:
parent
57c10174ec
commit
5253ce6b65
3 changed files with 21 additions and 12 deletions
|
@ -1,5 +1,3 @@
|
|||
use std::rc::Rc;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
|
@ -7,14 +5,18 @@ fn main() {
|
|||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let login = use_callback!(cx, || |evt| async {
|
||||
//
|
||||
let login = use_callback!(cx, || move |evt: MouseEvent| async move {
|
||||
let res = reqwest::get("https://dog.ceo/api/breeds/list/all")
|
||||
.await
|
||||
.unwrap()
|
||||
.text()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
println!("{}, ", res);
|
||||
});
|
||||
|
||||
cx.render(rsx! {
|
||||
button {
|
||||
onclick: login,
|
||||
"Click me!"
|
||||
}
|
||||
button { onclick: login, "Click me!" }
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use dioxus::prelude::*;
|
||||
use std::{collections::HashMap, marker::PhantomData};
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn main() {
|
||||
dioxus_desktop::launch(|cx| {
|
||||
|
|
|
@ -5,11 +5,18 @@ use std::future::Future;
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! use_callback {
|
||||
($cx:ident, || || $($rest:tt)*) => { use_callback( $cx, (), |_| $($rest)* ) };
|
||||
($cx:ident, || |$myarg:ident| $($rest:tt)*) => {
|
||||
// ($cx:ident, || || $($rest:tt)*) => { use_callback( $cx, (), |_| $($rest)* ) };
|
||||
// ($cx:ident, || || $($rest:tt)*) => { use_callback( $cx, (), |_| $($rest)* ) };
|
||||
($cx:ident, || $($rest:tt)*) => {
|
||||
use_callback(
|
||||
$cx,
|
||||
|| |$myarg| async {}
|
||||
move || $($rest)*
|
||||
)
|
||||
};
|
||||
($cx:ident, |$($args:tt),* | $($rest:tt)*) => {
|
||||
use_callback(
|
||||
$cx,
|
||||
move || $($rest)*
|
||||
)
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue