Skip to main content

dioxus_hooks/
use_after_suspense_resolved.rs

1use dioxus_core::{use_hook, Runtime};
2
3/// Run a closure after the suspense boundary this is under is resolved. The
4/// closure will be run immediately if the suspense boundary is already resolved
5/// or the scope is not under a suspense boundary.
6pub fn use_after_suspense_resolved(suspense_resolved: impl FnOnce() + 'static) {
7    use_hook(|| {
8        // If this is under a suspense boundary, we need to check if it is resolved
9        match Runtime::current().suspense_context() {
10            Some(context) => {
11                // If it is suspended, run the closure after the suspense is resolved
12                context.after_suspense_resolved(suspense_resolved)
13            }
14            None => {
15                // Otherwise, just run the resolved closure immediately
16                suspense_resolved();
17            }
18        }
19    })
20}