mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-22 12:13:04 +00:00
20d146d9bd
* improve documentation for the fullstack server context * Add a section about axum integration to the crate root docs * make serve_dioxus_application accept the cfg builder directly * remove unused server_fn module * improve fullstack config docs * improve documentation for the server function macro * fix axum router extension link * Fix doc tests * Fix launch builder * Simplify the launch builder * don't re-export launch in the prelude * refactor fullstack launch * Fix fullstack launch builder * Update static generation with the new builder api * fix some formatting/overly broad launch replacements * fix custom menu example * fix fullstack/static generation examples * Fix static generation launch * A few small formatting fixes * Fix a few doc tests * implement LaunchConfig for serve configs * fix fullstack launch with separate web and server launch methods * fix check with all features * dont expose inner core module * clippy and check * fix readme --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
72 lines
1.7 KiB
Rust
72 lines
1.7 KiB
Rust
//! Optional props
|
|
//!
|
|
//! This example demonstrates how to use optional props in your components. The `Button` component has several props,
|
|
//! and we use a variety of attributes to set them.
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
fn main() {
|
|
dioxus::launch(app);
|
|
}
|
|
|
|
fn app() -> Element {
|
|
rsx! {
|
|
// We can set some of the props, and the rest will be filled with their default values
|
|
// By default `c` can take a `None` value, but `d` is required to wrap a `Some` value
|
|
Button {
|
|
a: "asd".to_string(),
|
|
// b can be omitted, and it will be filled with its default value
|
|
c: "asd".to_string(),
|
|
d: Some("asd".to_string()),
|
|
e: Some("asd".to_string()),
|
|
}
|
|
|
|
Button {
|
|
a: "asd".to_string(),
|
|
b: "asd".to_string(),
|
|
|
|
// We can omit the `Some` on `c` since Dioxus automatically transforms Option<T> into optional
|
|
c: "asd".to_string(),
|
|
d: Some("asd".to_string()),
|
|
e: "asd".to_string(),
|
|
}
|
|
|
|
// `b` and `e` are omitted
|
|
Button {
|
|
a: "asd".to_string(),
|
|
c: "asd".to_string(),
|
|
d: Some("asd".to_string()),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Props, PartialEq, Clone)]
|
|
struct ButtonProps {
|
|
a: String,
|
|
|
|
#[props(default)]
|
|
b: String,
|
|
|
|
c: Option<String>,
|
|
|
|
#[props(!optional)]
|
|
d: Option<String>,
|
|
|
|
#[props(optional)]
|
|
e: SthElse<String>,
|
|
}
|
|
|
|
type SthElse<T> = Option<T>;
|
|
|
|
#[allow(non_snake_case)]
|
|
fn Button(props: ButtonProps) -> Element {
|
|
rsx! {
|
|
button {
|
|
"{props.a} | "
|
|
"{props.b:?} | "
|
|
"{props.c:?} | "
|
|
"{props.d:?} | "
|
|
"{props.e:?}"
|
|
}
|
|
}
|
|
}
|