From 7a4a0ca181536ce3fbd18d75cfe82d818f0ad3de Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Sat, 4 Oct 2025 11:06:11 -0700 Subject: [PATCH] move before_render and after_render to their respective hooks --- packages/core/src/global_context.rs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/packages/core/src/global_context.rs b/packages/core/src/global_context.rs index d77f3923c..d5a64ffc8 100644 --- a/packages/core/src/global_context.rs +++ b/packages/core/src/global_context.rs @@ -422,7 +422,7 @@ pub fn use_drop(destroy: D) { /// This function will always be called before dioxus tries to render your component. This should be used for safely handling /// early returns pub fn use_before_render(f: impl FnMut() + 'static) { - use_hook(|| before_render(f)); + use_hook(|| Runtime::with_current_scope(|cx| cx.push_before_render(f))); } /// Push this function to be run after the next render @@ -430,19 +430,7 @@ pub fn use_before_render(f: impl FnMut() + 'static) { /// This function will always be called before dioxus tries to render your component. This should be used for safely handling /// early returns pub fn use_after_render(f: impl FnMut() + 'static) { - use_hook(|| after_render(f)); -} - -/// Push a function to be run before the next render -/// This is a hook and will always run, so you can't unschedule it -/// Will run for every progression of suspense, though this might change in the future -pub fn before_render(f: impl FnMut() + 'static) { - Runtime::with_current_scope(|cx| cx.push_before_render(f)); -} - -/// Push a function to be run after the render is complete, even if it didn't complete successfully -pub fn after_render(f: impl FnMut() + 'static) { - Runtime::with_current_scope(|cx| cx.push_after_render(f)); + use_hook(|| Runtime::with_current_scope(|cx| cx.push_after_render(f))); } /// Use a hook with a cleanup function