added some docs to use_cookie and the actix feature

This commit is contained in:
Maccesch 2024-01-23 15:39:52 +00:00
parent 5c0503d022
commit 383e8ad689
4 changed files with 25 additions and 15 deletions

1
.idea/leptos-use.iml generated
View file

@ -64,6 +64,7 @@
<sourceFolder url="file://$MODULE_DIR$/examples/use_device_pixel_ratio/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/examples/use_element_bounding/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/examples/use_mouse_in_element/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/examples/use_cookie/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/examples/use_event_listener/target" />
<excludeFolder url="file://$MODULE_DIR$/target" />
<excludeFolder url="file://$MODULE_DIR$/docs/book/book" />

View file

@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### New Functions 🚀
- `use_cookie`
- `use_cookie` (thanks to @rakshith-ravi)
- `use_mouse_in_element`
- `use_device_pixel_ratio` (thanks to @mondeja)
- `use_element_bounding`

View file

@ -104,6 +104,7 @@ features = [
]
[features]
actix = ["dep:actix-web"]
axum = ["dep:leptos_axum"]
docs = []
math = ["num"]

View file

@ -16,21 +16,29 @@ use cookie::Cookie;
/// #
/// # #[component]
/// # fn Demo() -> impl IntoView {
/// if let Some(cookie) = use_cookie("auth") {
/// view! {
/// <div>
/// format!("'auth' cookie set to `{}`", cookie.value())
/// </div>
/// }.into_view()
/// } else {
/// view! {
/// <div>
/// "No 'auth' cookie set"
/// </div>
/// }.into_view()
/// }
/// if let Some(cookie) = use_cookie("auth") {
/// view! {
/// <div>
/// format!("'auth' cookie set to `{}`", cookie.value())
/// </div>
/// }.into_view()
/// } else {
/// view! {
/// <div>
/// "No 'auth' cookie set"
/// </div>
/// }.into_view()
/// }
/// # }
/// ```
///
/// Server-Side Rendering
///
/// This works equally well on the server or the client.
/// On the server this function gets the cookie from the HTTP request header.
///
/// If you're using `axum` you have to enable the `"axum"` feature in your Cargo.toml.
/// In case it's `actix-web` enable the feature `"actix"`.
pub fn use_cookie(cookie_name: &str) -> Option<Cookie<'static>> {
let cookies;
#[cfg(feature = "ssr")]
@ -39,7 +47,7 @@ pub fn use_cookie(cookie_name: &str) -> Option<Cookie<'static>> {
use leptos::expect_context;
let headers;
#[cfg(not(feature = "axum"))]
#[cfg(feature = "actix")]
{
headers = expect_context::<actix_web::HttpRequest>().headers().clone();
}