wip: polish some more things

This commit is contained in:
Jonathan Kelley committed 2021-12-29 21:28:28 -05:00
1 parent 2d58d380be
commit 14961023f9
32 files changed
+265 -370

No files matched your search

+8 -8
View File
@@ -64,7 +64,7 @@ Here's what a few common tasks look like in Dioxus:
Nested components with children and internal state:
```rust
fn App(cx: Scope<()>) -> Element {
fn App(cx: Scope) -> Element {
cx.render(rsx!( Toggle { "Toggle me" } ))
}
@@ -86,7 +86,7 @@ fn Toggle(cx: Scope<ToggleProps>) -> Element {
Controlled inputs:
```rust
fn App(cx: Scope<()>) -> Element {
fn App(cx: Scope) -> Element {
let value = use_state(&cx, String::new);
cx.render(rsx!(
input {
@@ -100,7 +100,7 @@ fn App(cx: Scope<()>) -> Element {
Lists and Conditional rendering:
```rust
fn App(cx: Scope<()>) -> Element {
fn App(cx: Scope) -> Element {
let list = (0..10).map(|i| {
rsx!(li { key: "{i}", "Value: {i}" })
});
@@ -128,7 +128,7 @@ static App: Component = |cx, _| rsx!(cx, div {"hello world!"});
Borrowed prop contents:
```rust
fn App(cx: Scope<()>) -> Element {
fn App(cx: Scope) -> Element {
let name = use_state(&cx, || String::from("example"));
rsx!(cx, Child { title: name.as_str() })
}
@@ -145,12 +145,12 @@ Global State
```rust
struct GlobalState { name: String }
fn App(cx: Scope<()>) -> Element {
fn App(cx: Scope) -> Element {
use_provide_shared_state(cx, || GlobalState { name: String::from("Toby") })
rsx!(cx, Leaf {})
}
fn Leaf(cx: Scope<()>) -> Element {
fn Leaf(cx: Scope) -> Element {
let state = use_consume_shared_state::<GlobalState>(cx)?;
rsx!(cx, "Hello {state.name}")
}
@@ -166,7 +166,7 @@ enum Route {
Post(id)
}
fn App(cx: Scope<()>) -> Element {
fn App(cx: Scope) -> Element {
let route = use_router(cx, Route::parse);
cx.render(rsx!(div {
{match route {
@@ -179,7 +179,7 @@ fn App(cx: Scope<()>) -> Element {
Suspense
```rust
fn App(cx: Scope<()>) -> Element {
fn App(cx: Scope) -> Element {
let doggo = use_suspense(cx,
|| async { reqwest::get("https://dog.ceo/api/breeds/image/random").await.unwrap().json::<Response>().await.unwrap() },
|response| cx.render(rsx!( img { src: "{response.message}" }))