Skip to content

Commit 0e818ba

Browse files
committed
Update doc
1 parent 9f2f258 commit 0e818ba

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

website/docs/concepts/function-components/properties.mdx

+28-1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,28 @@ fn App() -> Html {
263263
}
264264
```
265265

266+
## Automatically generate properties (autoprops)
267+
268+
In order to streamline your development process, you can also use the macro
269+
`#[autoprops]` that will automatically generate the `Properties` struct for you.
270+
271+
```rust
272+
use yew::prelude::*;
273+
274+
#[autoprops]
275+
#[function_component]
276+
fn Greetings(
277+
#[prop_or("Hello".into())]
278+
message: AttrValue,
279+
#[prop_or("World".into())]
280+
name: AttrValue,
281+
) -> Html {
282+
html! {<>{message}{name}</>}
283+
}
284+
285+
// The properties struct "GreetingsProps" will be generated automatically.
286+
```
287+
266288
## Evaluation Order
267289

268290
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:
296318
**Why is this bad?** Interior mutability (such as with `RefCell`, `Mutex`, etc.) should
297319
_generally_ be avoided. It can cause problems with re-renders (Yew doesn't know when the state has changed)
298320
so you may have to manually force a render. Like all things, it has its place. Use it with caution.
299-
3. You tell us. Did you run into an edge-case you wish you knew about earlier? Feel free to create an issue
321+
3. Using `Vec` type instead of `IArray`. <br />
322+
**Why is this bad?** `Vec`, just like `String`, can also be expensive to clone. `IArray` is either
323+
a reference-counted slice (`Rc<T>`) or a `&'static [T]`, thus very cheap to clone.<br />
324+
**Note**: `IArray` can be imported from [implicit-clone](https://crates.io/crates/implicit-clone)
325+
See that crate to learn more.
326+
4. You tell us. Did you run into an edge-case you wish you knew about earlier? Feel free to create an issue
300327
or PR a fix to this documentation.
301328

302329
## yew-autoprops

0 commit comments

Comments
 (0)