dioxus_hooks/
lib.rs

1#![doc = include_str!("../README.md")]
2#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
3#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
4
5#[macro_export]
6/// A helper macro for cloning multiple values at once
7///
8/// # Usage
9///
10///
11/// ```
12/// # use dioxus::prelude::*;
13/// #
14/// # #[derive(Props, PartialEq, Clone)]
15/// # struct Props {
16/// #    prop: String,
17/// # }
18/// # fn Component(props: Props) -> Element {
19///
20/// let (data) = use_signal(|| {});
21///
22/// let handle_thing = move |_| {
23///     to_owned![data, props.prop];
24///     spawn(async move {
25///         // do stuff
26///     });
27/// };
28/// # handle_thing(());
29/// # VNode::empty() }
30/// ```
31macro_rules! to_owned {
32    // Rule matching simple symbols without a path
33    ($es:ident $(, $($rest:tt)*)?) => {
34        #[allow(unused_mut)]
35        let mut $es = $es.to_owned();
36        $( to_owned![$($rest)*] )?
37    };
38
39    // We need to find the last element in a path, for this we need to unstack the path part by
40    // part using, separating what we have with a '@'
41    ($($deref:ident).* $(, $($rest:tt)*)?) => {
42        to_owned![@ $($deref).* $(, $($rest)*)?]
43    };
44
45    // Take the head of the path and add it to the list of $deref
46    ($($deref:ident)* @ $head:ident $( . $tail:ident)+ $(, $($rest:tt)*)?) => {
47        to_owned![$($deref)* $head @ $($tail).+ $(, $($rest)*)?]
48    };
49    // We have exhausted the path, use the last as a name
50    ($($deref:ident)* @ $last:ident $(, $($rest:tt)*)? ) => {
51        #[allow(unused_mut)]
52        let mut $last = $($deref .)* $last .to_owned();
53        $(to_owned![$($rest)*])?
54    };
55}
56
57mod use_callback;
58pub use use_callback::*;
59
60mod use_on_destroy;
61pub use use_on_destroy::*;
62
63mod use_context;
64pub use use_context::*;
65
66mod use_coroutine;
67pub use use_coroutine::*;
68
69mod use_future;
70pub use use_future::*;
71
72mod use_reactive;
73pub use use_reactive::*;
74
75// mod use_sorted;
76// pub use use_sorted::*;
77
78mod use_resource;
79pub use use_resource::*;
80
81mod use_effect;
82pub use use_effect::*;
83
84mod use_memo;
85pub use use_memo::*;
86
87mod use_root_context;
88pub use use_root_context::*;
89
90mod use_hook_did_run;
91pub use use_hook_did_run::*;
92
93mod use_signal;
94pub use use_signal::*;
95
96mod use_set_compare;
97pub use use_set_compare::*;