use crate::api::{self, User}; use leptos::*; use leptos_router::*; #[component] pub fn User() -> impl IntoView { let params = use_params_map(); let user = create_resource( move || params().get("id").cloned().unwrap_or_default(), move |id| async move { if id.is_empty() { None } else { api::fetch_api::(&api::user(&id)).await } }, ); view! {
{move || user.get().map(|user| match user { None => view! {

"User not found."

}.into_any(), Some(user) => view! {

"User: " {&user.id}

  • "Created: " {user.created}
  • "Karma: " {user.karma}
  • {user.about.as_ref().map(|about| view! {
  • })}
}.into_any() })}
} }