This commit is contained in:
marc2332 2023-06-28 20:01:28 +02:00
parent e413ea4019
commit bf0247a7dc
No known key found for this signature in database
GPG key ID: C06A66E2828F72E1

View file

@ -2,11 +2,14 @@
[`use_effect`](https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_effect.html) provides a future that executes after the hooks have been applied.
Whenever the hooks dependencies change, the future will be re-evaluated. This is useful to syncrhonize with external events.
Whenever the hooks [dependencies](#dependencies) change, the future will be re-evaluated. This is useful to syncrhonize with external events.
If a future is pending when the dependencies change, the previous future will be allowed to continue
> The `dependencies` is tuple of references to values that are `PartialEq + Clone`.
## Dependencies
You might want to call `use_effect` only when some value changes. For example, you might want to fetch a user's data only when the user id changes. You can provide a tuple of "dependencies" to the hook. It will automatically re-run the future when any of those dependencies change.
Example:
```rust, no_run
#[inline_props]
@ -29,4 +32,4 @@ fn app(cx: Scope) -> Element {
Profile { id: "dioxusLabs" }
)
}
```
```