1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use dioxus_hooks::try_use_context;
use dioxus_signals::{Readable, Signal};

#[derive(Default, Clone)]
pub struct ActivableRouteContext(pub Signal<bool>);

impl ActivableRouteContext {
    pub fn is_active(&self) -> bool {
        *self.0.read()
    }
}

pub fn use_activable_route() -> bool {
    let ctx = try_use_context::<ActivableRouteContext>();

    if let Some(ctx) = ctx {
        ctx.is_active()
    } else {
        false
    }
}