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

+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()