diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b3bff0..3bbcf5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### New Functions 🚀 +- `use_to_string` - `is_err` - `is_ok` - `is_none` diff --git a/docs/book/src/SUMMARY.md b/docs/book/src/SUMMARY.md index 697f3de..cb2940f 100644 --- a/docs/book/src/SUMMARY.md +++ b/docs/book/src/SUMMARY.md @@ -71,6 +71,7 @@ - [use_debounce_fn](utilities/use_debounce_fn.md) - [use_supported](utilities/use_supported.md) - [use_throttle_fn](utilities/use_throttle_fn.md) +- [use_to_string](utilities/use_to_string.md) # Intl diff --git a/docs/book/src/utilities/use_to_string.md b/docs/book/src/utilities/use_to_string.md new file mode 100644 index 0000000..18e2a28 --- /dev/null +++ b/docs/book/src/utilities/use_to_string.md @@ -0,0 +1,3 @@ +# use_to_string + + diff --git a/examples/Cargo.toml b/examples/Cargo.toml index e664151..d30b47a 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -36,6 +36,7 @@ members = [ "use_scroll", "use_storage", "use_throttle_fn", + "use_to_string", "use_websocket", "use_window_focus", "use_window_scroll", diff --git a/src/lib.rs b/src/lib.rs index 9086995..17264ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,7 @@ cfg_if! { if #[cfg(web_sys_unstable_apis)] { }} mod on_click_outside; +mod use_to_string; mod is_err; mod is_ok; mod is_none; @@ -60,6 +61,7 @@ mod watch_throttled; mod whenever; pub use on_click_outside::*; +pub use use_to_string::*; pub use is_err::*; pub use is_ok::*; pub use is_none::*; diff --git a/src/use_to_string.rs b/src/use_to_string.rs new file mode 100644 index 0000000..b5b6b98 --- /dev/null +++ b/src/use_to_string.rs @@ -0,0 +1,23 @@ +use crate::utils::use_derive_signal; +use leptos::*; + +use_derive_signal!( + /// Reactive `ToString::to_string()`. + /// + /// ## Usage + /// + /// ``` + /// # use leptos::*; + /// # use leptos_use::use_to_string; + /// # + /// # #[component] + /// # fn Demo(cx: Scope) -> impl IntoView { + /// let (number, set_number) = create_signal(cx, 3.14_f64); + /// let str = use_to_string::<_, f64>(cx, number); + /// # + /// # view! { cx, } + /// # } + /// ``` + use_to_string -> String + |value| value.to_string() +);