Skip to content

Commit

Permalink
Update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton committed Nov 1, 2023
1 parent 9f2f258 commit 0e818ba
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion website/docs/concepts/function-components/properties.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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`. <br />
**Why is this bad?** `Vec`, just like `String`, can also be expensive to clone. `IArray` is either
a reference-counted slice (`Rc<T>`) or a `&'static [T]`, thus very cheap to clone.<br />
**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
Expand Down

0 comments on commit 0e818ba

Please sign in to comment.