docs: more docs and an errorhandling example
This commit is contained in:
1 parent
9846e0947b
commit
3acd643afb
8 files changed
+378
-33
No files matched your search
@@ -108,7 +108,7 @@ There are a few different approaches to choosing when to update your state. You
|
||||
|
||||
When responding to user-triggered events, we'll want to "listen" for an event on some element in our component.
|
||||
|
||||
For example, let's say we provide a button to generate a new post. Whenever the user clicks the button, they get a new post. To achieve this functionality, we'll want to attach a function to the `on_click` method of `button`. Whenever the button is clicked, our function will run, and we'll get new Post data to work with.
|
||||
For example, let's say we provide a button to generate a new post. Whenever the user clicks the button, they get a new post. To achieve this functionality, we'll want to attach a function to the `onclick` method of `button`. Whenever the button is clicked, our function will run, and we'll get new Post data to work with.
|
||||
|
||||
```rust
|
||||
fn App(cx: Scope)-> Element {
|
||||
@@ -116,7 +116,7 @@ fn App(cx: Scope)-> Element {
|
||||
|
||||
cx.render(rsx!{
|
||||
button {
|
||||
on_click: move |_| set_post(PostData::random())
|
||||
onclick: move |_| set_post(PostData::random())
|
||||
"Generate a random post"
|
||||
}
|
||||
Post { props: &post }
|
||||
@@ -128,10 +128,10 @@ We'll dive much deeper into event listeners later.
|
||||
|
||||
### Updating state asynchronously
|
||||
|
||||
We can also update our state outside of event listeners with `futures` and `coroutines`.
|
||||
We can also update our state outside of event listeners with `futures` and `coroutines`.
|
||||
|
||||
- `Futures` are Rust's version of promises that can execute asynchronous work by an efficient polling system. We can submit new futures to Dioxus either through `push_future` which returns a `TaskId` or with `spawn`.
|
||||
- `Coroutines` are asynchronous blocks of our component that have the ability to cleanly interact with values, hooks, and other data in the component.
|
||||
- `Coroutines` are asynchronous blocks of our component that have the ability to cleanly interact with values, hooks, and other data in the component.
|
||||
|
||||
Since coroutines and Futures stick around between renders, the data in them must be valid for the `'static` lifetime. We must explicitly declare which values our task will rely on to avoid the `stale props` problem common in React.
|
||||
|
||||
|
||||
Reference in new issue
Block a user