wip: more examples

This commit is contained in:
Jonathan Kelley committed 2021-07-06 12:13:00 -04:00
1 parent 904b26f711
commit 11f89e5d33
27 files changed
+64 -57

No files matched your search

+3 -3
View File
@@ -19,9 +19,9 @@ enum Operator {
}
static App: FC<()> = |cx| {
let cur_val = use_state_new(&cx, || 0.0_f64);
let operator = use_state_new(&cx, || None as Option<Operator>);
let display_value = use_state_new(&cx, || "".to_string());
let cur_val = use_state(&cx, || 0.0_f64);
let operator = use_state(&cx, || None as Option<Operator>);
let display_value = use_state(&cx, || "".to_string());
let clear_display = display_value.eq("0");
let clear_text = if clear_display { "C" } else { "AC" };
+1 -1
View File
@@ -2,7 +2,7 @@ use dioxus::prelude::*;
fn main() {}
static Example: FC<()> = |cx| {
let (g, set_g) = use_state(&cx, || 0);
let (g, set_g) = use_state_classic(&cx, || 0);
let v = (0..10).map(move |f| {
rsx!(li {
onclick: move |_| set_g(10)
+18
View File
@@ -0,0 +1,18 @@
//! Example: README.md showcase
//!
//! The example from the README.md
use dioxus::prelude::*;
fn main() {
dioxus::web::launch(Example)
}
fn Example(cx: Context<()>) -> VNode {
let name = use_state(&cx, || "..?");
cx.render(rsx! {
h1 { "Hello, {name}" }
button { "?", onclick: move |_| name.set("world!")}
button { "?", onclick: move |_| name.set("Dioxus 🎉")}
})
}
+2 -2
View File
@@ -85,7 +85,7 @@ static AntipatternNestedFragments: FC<()> = |cx| {
/// recognize from the function signature, but Dioxus will not update the "live" version of state. Calling `set_state`
/// merely places a new value in the queue and schedules the component for a future update.
static AntipaternRelyingOnSetState: FC<()> = |cx| {
let (state, set_state) = use_state(&cx, || "Hello world");
let (state, set_state) = use_state_classic(&cx, || "Hello world");
set_state("New state");
// This will return false! `state` will *still* be "Hello world"
assert!(state == &"New state");
@@ -126,7 +126,7 @@ static AntipatternMisusedHooks: FC<MisuedHooksProps> = |cx| {
if cx.should_render_state {
// do not place a hook in the conditional!
// prefer to move it out of the conditional
let (state, set_state) = use_state(&cx, || "hello world");
let (state, set_state) = use_state_classic(&cx, || "hello world");
rsx!(in cx, div { "{state}" })
} else {
rsx!(in cx, div { "Not rendering state" })
+1 -1
View File
@@ -2,7 +2,7 @@ use dioxus::prelude::*;
fn main() {}
static Example: FC<()> = |cx| {
let (g, set_g) = use_state(&cx, || 0);
let (g, set_g) = use_state_classic(&cx, || 0);
let v = (0..10).map(|f| {
rsx! {
li {
+1 -1
View File
@@ -11,7 +11,7 @@ fn main() {}
/// We can use `set_name` in multiple closures; the closures automatically *copy* the reference to set_name.
static ButtonList: FC<()> = |cx| {
let (name, set_name) = use_state(&cx, || "...?");
let (name, set_name) = use_state_classic(&cx, || "...?");
let names = ["jack", "jill", "john", "jane"]
.iter()
+1 -1
View File
@@ -16,7 +16,7 @@ fn main() {
}
static App: FC<()> = |cx| {
let (count, set_count) = use_state(&cx, || 0);
let (count, set_count) = use_state_classic(&cx, || 0);
cx.render(rsx! {
div {