21 releases

new 0.2.4 Mar 21, 2023
0.2.3 Mar 13, 2023
0.2.1 Feb 26, 2023
0.1.3 Jan 28, 2023
0.0.3 Nov 27, 2022

#219 in WebAssembly

Download history 147/week @ 2022-12-03 88/week @ 2022-12-10 130/week @ 2022-12-17 256/week @ 2022-12-24 150/week @ 2022-12-31 141/week @ 2023-01-07 157/week @ 2023-01-14 127/week @ 2023-01-21 251/week @ 2023-01-28 85/week @ 2023-02-04 118/week @ 2023-02-11 195/week @ 2023-02-18 443/week @ 2023-02-25 557/week @ 2023-03-04 559/week @ 2023-03-11 685/week @ 2023-03-18

2,264 downloads per month
Used in 6 crates

MIT license

79KB
965 lines

Leptos Meta

Leptos Meta allows you to modify content in a document’s <head> from within components using the Leptos web framework.

Document metadata is updated automatically when running in the browser. For server-side rendering, after the component tree is rendered to HTML, [MetaContext::dehydrate] can generate HTML that should be injected into the <head> of the HTML document being rendered.

use leptos::*;
use leptos_meta::*;

#[component]
fn MyApp(cx: Scope) -> impl IntoView {
    let (name, set_name) = create_signal(cx, "Alice".to_string());

    view! { cx,
      <Title
        // reactively sets document.title when `name` changes
        text=name
        // applies the `formatter` function to the `text` value
        formatter=|text| format!("{text}” is your name")
      />
      <main>
        <input
          prop:value=name
          on:input=move |ev| set_name(event_target_value(&ev))
        />
      </main>
    }
}

Feature Flags

  • csr Client-side rendering: Generate DOM nodes in the browser
  • ssr Server-side rendering: Generate an HTML string (typically on the server)
  • hydrate Hydration: use this to add interactivity to an SSRed Leptos app
  • stable By default, Leptos requires nightly Rust, which is what allows the ergonomics of calling signals as functions. Enable this feature to support stable Rust.

Important Note: You must enable one of csr, hydrate, or ssr to tell Leptos which mode your app is operating in.

Dependencies

~17–27MB
~518K SLoC