chore: finish tweaking context api
This commit is contained in:
1 parent
99a818996e
commit
df4a1b6c7a
12 files changed
+76
-81
No files matched your search
@@ -1,4 +1,4 @@
|
||||
use crate::{ParsedRoute, RouteContext, RouterCore, RouterService};
|
||||
use crate::{ParsedRoute, RouteContext, RouterContext};
|
||||
use dioxus::core::{ScopeId, ScopeState};
|
||||
use std::{borrow::Cow, str::FromStr, sync::Arc};
|
||||
use url::Url;
|
||||
@@ -7,11 +7,11 @@ use url::Url;
|
||||
/// context of a [`Router`]. If this function is called outside of a `Router`
|
||||
/// component it will panic.
|
||||
pub fn use_route(cx: &ScopeState) -> &UseRoute {
|
||||
let handle = cx.use_hook(|| {
|
||||
let router = cx
|
||||
.consume_context::<RouterService>()
|
||||
.expect("Cannot call use_route outside the scope of a Router component");
|
||||
let router = cx
|
||||
.consume_context::<RouterContext>()
|
||||
.expect("Cannot call use_route outside the scope of a Router component");
|
||||
|
||||
let handle = cx.use_hook(|| {
|
||||
let route_context = cx.consume_context::<RouteContext>();
|
||||
|
||||
router.subscribe_onchange(cx.scope_id());
|
||||
@@ -115,7 +115,7 @@ impl UseRoute {
|
||||
// and reveal our cached version of UseRoute to the component.
|
||||
struct UseRouteListener {
|
||||
state: UseRoute,
|
||||
router: Arc<RouterCore>,
|
||||
router: RouterContext,
|
||||
scope: ScopeId,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
use crate::RouterService;
|
||||
use dioxus::core::ScopeState;
|
||||
use crate::RouterContext;
|
||||
use dioxus::{core::ScopeState, prelude::use_context};
|
||||
|
||||
/// This hook provides access to the `RouterService` for the app.
|
||||
pub fn use_router(cx: &ScopeState) -> &RouterService {
|
||||
cx.use_hook(|| {
|
||||
cx.consume_context::<RouterService>()
|
||||
.expect("Cannot call use_route outside the scope of a Router component")
|
||||
})
|
||||
pub fn use_router(cx: &ScopeState) -> &RouterContext {
|
||||
use_context::<RouterContext>(cx)
|
||||
.expect("Cannot call use_route outside the scope of a Router component")
|
||||
}
|
||||
Reference in new issue
Block a user