Intigrate macro with router hooks and components
This commit is contained in:
1 parent
ef6551a6cd
commit
e4b8fbfafe
37 files changed
+1442
-3009
No files matched your search
@@ -0,0 +1,29 @@
|
||||
use dioxus::prelude::*;
|
||||
|
||||
use crate::{hooks::use_route, routable::Routable};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct OutletContext {
|
||||
pub current_level: usize,
|
||||
}
|
||||
|
||||
pub(crate) fn use_outlet_context(cx: &ScopeState) -> &OutletContext {
|
||||
let outlet_context = use_context(cx).unwrap();
|
||||
outlet_context
|
||||
}
|
||||
|
||||
impl OutletContext {
|
||||
pub(crate) fn render<R: Routable + Clone>(cx: &ScopeState) -> Element<'_> {
|
||||
let outlet = use_outlet_context(cx);
|
||||
let current_level = outlet.current_level;
|
||||
cx.provide_context({
|
||||
OutletContext {
|
||||
current_level: current_level + 1,
|
||||
}
|
||||
});
|
||||
|
||||
use_route::<R>(cx)
|
||||
.expect("Outlet must be inside of a router")
|
||||
.render(cx, current_level)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user