From 0e818ba7fb89c3f1a15c2710d8f0139b3cc03067 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Wed, 1 Nov 2023 11:34:57 +0100 Subject: [PATCH] Update doc --- .../function-components/properties.mdx | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/website/docs/concepts/function-components/properties.mdx b/website/docs/concepts/function-components/properties.mdx index d331425ec92..c6e1c09002a 100644 --- a/website/docs/concepts/function-components/properties.mdx +++ b/website/docs/concepts/function-components/properties.mdx @@ -263,6 +263,28 @@ fn App() -> Html { } ``` +## Automatically generate properties (autoprops) + +In order to streamline your development process, you can also use the macro +`#[autoprops]` that will automatically generate the `Properties` struct for you. + +```rust +use yew::prelude::*; + +#[autoprops] +#[function_component] +fn Greetings( + #[prop_or("Hello".into())] + message: AttrValue, + #[prop_or("World".into())] + name: AttrValue, +) -> Html { + html! {<>{message}{name}} +} + +// The properties struct "GreetingsProps" will be generated automatically. +``` + ## Evaluation Order Props are evaluated in the order they're specified, as shown by the following example: @@ -296,7 +318,12 @@ These include, but are not limited to: **Why is this bad?** Interior mutability (such as with `RefCell`, `Mutex`, etc.) should _generally_ be avoided. It can cause problems with re-renders (Yew doesn't know when the state has changed) so you may have to manually force a render. Like all things, it has its place. Use it with caution. -3. You tell us. Did you run into an edge-case you wish you knew about earlier? Feel free to create an issue +3. Using `Vec` type instead of `IArray`.
+ **Why is this bad?** `Vec`, just like `String`, can also be expensive to clone. `IArray` is either + a reference-counted slice (`Rc`) or a `&'static [T]`, thus very cheap to clone.
+ **Note**: `IArray` can be imported from [implicit-clone](https://crates.io/crates/implicit-clone) + See that crate to learn more. +4. You tell us. Did you run into an edge-case you wish you knew about earlier? Feel free to create an issue or PR a fix to this documentation. ## yew-autoprops