Improve use_hook_did_run docs (#4554)
This commit is contained in:
1 parent
8b482f4252
commit
abfd39d90e
1 file changed
+5
-3
@@ -1,7 +1,9 @@
|
||||
use dioxus_core::{use_after_render, use_before_render, use_hook};
|
||||
use dioxus_signals::{CopyValue, WritableExt};
|
||||
|
||||
/// A hook that uses before/after lifecycle hooks to determine if the hook was run
|
||||
/// A utility lifecycle hook that is intended to be used inside other hooks to determine if the outer hook has ran this render.
|
||||
/// The provided callback is executed after each render.
|
||||
/// The value will only be true if the containing outer hook is executed.
|
||||
#[doc = include_str!("../docs/rules_of_hooks.md")]
|
||||
#[doc = include_str!("../docs/moving_state_around.md")]
|
||||
pub fn use_hook_did_run(mut handler: impl FnMut(bool) + 'static) {
|
||||
@@ -10,9 +12,9 @@ pub fn use_hook_did_run(mut handler: impl FnMut(bool) + 'static) {
|
||||
// Before render always set the value to false
|
||||
use_before_render(move || did_run_.set(false));
|
||||
|
||||
// Only when this hook is hit do we want to set the value to true
|
||||
// Only when the outer hook is run do we want to set the value to true
|
||||
did_run_.set(true);
|
||||
|
||||
// After render, we can check if the hook was run
|
||||
// After render, we can check if the outer hook was run
|
||||
use_after_render(move || handler(did_run_()));
|
||||
}
|
||||
Reference in new issue
Block a user