Skip to content

Commit

Permalink
Add 'create_query_signal_with_options' version of 'create_query_signal'
Browse files Browse the repository at this point in the history
  • Loading branch information
kryesh committed Apr 11, 2024
1 parent e29d31e commit a1287e8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion router/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ use std::{rc::Rc, str::FromStr};
pub fn create_query_signal<T>(
key: impl Into<Oco<'static, str>>,
) -> (Memo<Option<T>>, SignalSetter<Option<T>>)
where
T: FromStr + ToString + PartialEq,
{
create_query_signal_with_options::<T>(key, NavigateOptions::default())
}

#[track_caller]
pub fn create_query_signal_with_options<T>(
key: impl Into<Oco<'static, str>>,
nav_options: NavigateOptions,
) -> (Memo<Option<T>>, SignalSetter<Option<T>>)
where
T: FromStr + ToString + PartialEq,
{
Expand All @@ -65,6 +76,7 @@ where

let set = SignalSetter::map(move |value: Option<T>| {
let mut new_query_map = query_map.get();
let nav_options = nav_options.clone();
match value {
Some(value) => {
new_query_map.insert(key.to_string(), value.to_string());
Expand All @@ -77,7 +89,7 @@ where
let path = location.pathname.get_untracked();
let hash = location.hash.get_untracked();
let new_url = format!("{path}{qs}{hash}");
navigate(&new_url, NavigateOptions::default());
navigate(&new_url, nav_options);
});

(get, set)
Expand Down

0 comments on commit a1287e8

Please sign in to comment.