Improve inline docs (#2460)
Improve inline docs * improve incorrect event handler return error message * Improve event handler docs * document the eval functions * document spawn and common spawn errors * fix event handler docs * add notes about how you use attributes and elements in rsx * add doc aliases for attributes and events we rename * add some more aliases for common search terms * don't doc ignore any public examples in core * don't ignore public doc examples in ssr * don't ignore examples in the dioxus package readme * add a warning when you launch without a renderer enabled * fix some outdated element docs * add a bunch of examples to resource * add notes about desktop events * add more docs for use_resource * add on_unimplemented hint to Dependency * fix some unresolved links * add examples to each of the router traits * add not implemented errors for router traits * add an example to the routable trait * expand rsx macro docs * improve memo docs * update the dioxus readme * mention dioxus crate features in the docs * fix a bunch of doc tests * fix html doc tests * fix router doc tests * fix dioxus signals doc tests * fix dioxus ssr doc tests * fix use_future example in the hooks cheat sheet * add a javascript alias for eval * fix hook explanation values * remove unused embed-doc-image dependency
This commit is contained in:
1 parent
054351139f
commit
0127501dbf
71 files changed
+4132
-1162
No files matched your search
@@ -4,41 +4,8 @@ use futures_util::StreamExt;
|
||||
|
||||
use crate::use_callback;
|
||||
|
||||
/// `use_effect` will subscribe to any changes in the signal values it captures
|
||||
/// effects will always run after first mount and then whenever the signal values change
|
||||
/// If the use_effect call was skipped due to an early return, the effect will no longer activate.
|
||||
/// ```rust
|
||||
/// # use dioxus::prelude::*;
|
||||
/// fn app() -> Element {
|
||||
/// let mut count = use_signal(|| 0);
|
||||
/// //the effect runs again each time count changes
|
||||
/// use_effect(move || println!("Count changed to {count}"));
|
||||
///
|
||||
/// rsx! {
|
||||
/// h1 { "High-Five counter: {count}" }
|
||||
/// button { onclick: move |_| count += 1, "Up high!" }
|
||||
/// button { onclick: move |_| count -= 1, "Down low!" }
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ## With non-reactive dependencies
|
||||
/// To add non-reactive dependencies, you can use the `use_reactive` hook.
|
||||
///
|
||||
/// Signals will automatically be added as dependencies, so you don't need to call this method for them.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # async fn sleep(delay: u32) {}
|
||||
///
|
||||
/// #[component]
|
||||
/// fn Comp(count: u32) -> Element {
|
||||
/// // Because the memo subscribes to `count` by adding it as a dependency, the memo will rerun every time `count` changes.
|
||||
/// use_effect(use_reactive((&count,), |(count,)| println!("Manually manipulate the dom") ));
|
||||
///
|
||||
/// todo!()
|
||||
/// }
|
||||
/// ```
|
||||
#[doc = include_str!("../docs/side_effects.md")]
|
||||
#[doc = include_str!("../docs/rules_of_hooks.md")]
|
||||
#[track_caller]
|
||||
pub fn use_effect(callback: impl FnMut() + 'static) -> Effect {
|
||||
let callback = use_callback(callback);
|
||||
|
||||
Reference in new issue
Block a user