Remove argument from use_hook closure (#496)

Also; update docs for said function
This commit is contained in:
Reinis Mazeiks authored and GitHub committed 2022-07-11 15:50:56 -04:00
1 parent 6ea076fa7f
commit d734dc5b46
29 files changed
+53 -55

No files matched your search

+1 -1
View File
@@ -77,7 +77,7 @@ pub struct LinkProps<'a> {
/// }
/// ```
pub fn Link<'a>(cx: Scope<'a, LinkProps<'a>>) -> Element {
let svc = cx.use_hook(|_| cx.consume_context::<Arc<RouterCore>>());
let svc = cx.use_hook(|| cx.consume_context::<Arc<RouterCore>>());
let LinkProps {
to,
+1 -1
View File
@@ -34,7 +34,7 @@ pub struct RedirectProps<'a> {
pub fn Redirect<'a>(cx: Scope<'a, RedirectProps<'a>>) -> Element {
let router = use_router(&cx);
let immediate_redirect = cx.use_hook(|_| {
let immediate_redirect = cx.use_hook(|| {
if let Some(from) = cx.props.from {
router.register_total_route(from.to_string(), cx.scope_id());
false
+2 -2
View File
@@ -28,10 +28,10 @@ pub struct RouteProps<'a> {
/// ```
pub fn Route<'a>(cx: Scope<'a, RouteProps<'a>>) -> Element {
let router_root = cx
.use_hook(|_| cx.consume_context::<Arc<RouterCore>>())
.use_hook(|| cx.consume_context::<Arc<RouterCore>>())
.as_ref()?;
cx.use_hook(|_| {
cx.use_hook(|| {
// create a bigger, better, longer route if one above us exists
let total_route = match cx.consume_context::<RouteContext>() {
Some(ctx) => ctx.total_route,
+1 -1
View File
@@ -37,7 +37,7 @@ pub struct RouterProps<'a> {
/// Will fallback to HashRouter is BrowserRouter is not available, or through configuration.
#[allow(non_snake_case)]
pub fn Router<'a>(cx: Scope<'a, RouterProps<'a>>) -> Element {
let svc = cx.use_hook(|_| {
let svc = cx.use_hook(|| {
cx.provide_context(RouterCore::new(
&cx,
RouterCfg {
+1 -1
View File
@@ -7,7 +7,7 @@ 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 handle = cx.use_hook(|| {
let router = cx
.consume_context::<RouterService>()
.expect("Cannot call use_route outside the scope of a Router component");
+1 -1
View File
@@ -3,7 +3,7 @@ use dioxus::core::ScopeState;
/// This hook provides access to the `RouterService` for the app.
pub fn use_router(cx: &ScopeState) -> &RouterService {
cx.use_hook(|_| {
cx.use_hook(|| {
cx.consume_context::<RouterService>()
.expect("Cannot call use_route outside the scope of a Router component")
})