added use_to_string

This commit is contained in:
Maccesch 2023-07-16 14:17:15 +01:00
parent 880eca30da
commit e529d110bc
6 changed files with 31 additions and 0 deletions

View file

@ -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`

View file

@ -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

View file

@ -0,0 +1,3 @@
# use_to_string
<!-- cmdrun python3 ../extract_doc_comment.py use_to_string -->

View file

@ -36,6 +36,7 @@ members = [
"use_scroll",
"use_storage",
"use_throttle_fn",
"use_to_string",
"use_websocket",
"use_window_focus",
"use_window_scroll",

View file

@ -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::*;

23
src/use_to_string.rs Normal file
View file

@ -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<T, T: ToString + 'static> -> String
|value| value.to_string()
);