polish: change in cx to cx
This commit is contained in:
1 parent
0ded32e184
commit
9971ff215d
21 files changed
+426
-320
No files matched your search
@@ -34,11 +34,11 @@ struct NoKeysProps {
|
||||
}
|
||||
static AntipatternNoKeys: FC<NoKeysProps> = |cx| {
|
||||
// WRONG: Make sure to add keys!
|
||||
rsx!(in cx, ul {
|
||||
rsx!(cx, ul {
|
||||
{cx.data.iter().map(|(k, v)| rsx!(li { "List item: {v}" }))}
|
||||
});
|
||||
// RIGHT: Like this:
|
||||
rsx!(in cx, ul {
|
||||
rsx!(cx, ul {
|
||||
{cx.data.iter().map(|(k, v)| rsx!(li { key: "{k}", "List item: {v}" }))}
|
||||
})
|
||||
};
|
||||
@@ -56,7 +56,7 @@ static AntipatternNoKeys: FC<NoKeysProps> = |cx| {
|
||||
/// an API for registering shared state without the ContextProvider pattern.
|
||||
static AntipatternNestedFragments: FC<()> = |cx| {
|
||||
// Try to avoid heavily nesting fragments
|
||||
rsx!(in cx,
|
||||
rsx!(cx,
|
||||
Fragment {
|
||||
Fragment {
|
||||
Fragment {
|
||||
@@ -125,9 +125,9 @@ static AntipatternMisusedHooks: FC<MisuedHooksProps> = |cx| {
|
||||
// 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").classic();
|
||||
rsx!(in cx, div { "{state}" })
|
||||
rsx!(cx, div { "{state}" })
|
||||
} else {
|
||||
rsx!(in cx, div { "Not rendering state" })
|
||||
rsx!(cx, div { "Not rendering state" })
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ pub static Example0: FC<MyProps> = |cx| {
|
||||
// which will do essentially the same thing as `cx.render`.
|
||||
//
|
||||
// In short:
|
||||
// `rsx!(in cx, ...)` is shorthand for `cx.render(rsx!(...))`
|
||||
// `rsx!(cx, ...)` is shorthand for `cx.render(rsx!(...))`
|
||||
#[derive(PartialEq, Props)]
|
||||
pub struct MyProps1 {
|
||||
should_show: bool,
|
||||
@@ -45,21 +45,21 @@ pub static Example1: FC<MyProps1> = |cx| {
|
||||
// With matching
|
||||
{match cx.should_show {
|
||||
true => cx.render(rsx!(div {"it is true!"})),
|
||||
false => rsx!(in cx, div {"it is false!"}),
|
||||
false => rsx!(cx, div {"it is false!"}),
|
||||
}}
|
||||
|
||||
// or with just regular conditions
|
||||
{if cx.should_show {
|
||||
rsx!(in cx, div {"it is true!"})
|
||||
rsx!(cx, div {"it is true!"})
|
||||
} else {
|
||||
rsx!(in cx, div {"it is false!"})
|
||||
rsx!(cx, div {"it is false!"})
|
||||
}}
|
||||
|
||||
// or with optional chaining
|
||||
{
|
||||
cx.should_show
|
||||
.then(|| rsx!(in cx, div {"it is false!"}))
|
||||
.unwrap_or_else(|| rsx!(in cx, div {"it is false!"}))
|
||||
.then(|| rsx!(cx, div {"it is false!"}))
|
||||
.unwrap_or_else(|| rsx!(cx, div {"it is false!"}))
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -81,9 +81,9 @@ pub static Example2: FC<MyProps2> = |cx| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
{match cx.color {
|
||||
Color::Green => rsx!(in cx, div {"it is Green!"}),
|
||||
Color::Yellow => rsx!(in cx, div {"it is Yellow!"}),
|
||||
Color::Red => rsx!(in cx, div {"it is Red!"}),
|
||||
Color::Green => rsx!(cx, div {"it is Green!"}),
|
||||
Color::Yellow => rsx!(cx, div {"it is Yellow!"}),
|
||||
Color::Red => rsx!(cx, div {"it is Red!"}),
|
||||
}}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -34,7 +34,7 @@ static ButtonList: FC<()> = |cx| {
|
||||
/// This shows how listeners may be without a visible change in the display.
|
||||
/// Check the console.
|
||||
static NonUpdatingEvents: FC<()> = |cx| {
|
||||
rsx!(in cx, div {
|
||||
rsx!(cx, div {
|
||||
button {
|
||||
onclick: move |_| log::info!("Did not cause any updates!")
|
||||
"Click me to log!"
|
||||
@@ -43,7 +43,7 @@ static NonUpdatingEvents: FC<()> = |cx| {
|
||||
};
|
||||
|
||||
static DisablePropogation: FC<()> = |cx| {
|
||||
rsx!(in cx,
|
||||
rsx!(cx,
|
||||
div {
|
||||
onclick: move |_| log::info!("event propogated to the div!")
|
||||
button {
|
||||
|
||||
@@ -19,8 +19,8 @@ pub static Example: FC<()> = |cx| {
|
||||
cx,
|
||||
|| surf::get(ENDPOINT).recv_json::<DogApi>(),
|
||||
|cx, res| match res {
|
||||
Ok(res) => rsx!(in cx, img { src: "{res.message}" }),
|
||||
Err(_) => rsx!(in cx, div { "No doggos for you :(" }),
|
||||
Ok(res) => rsx!(cx, img { src: "{res.message}" }),
|
||||
Err(_) => rsx!(cx, div { "No doggos for you :(" }),
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ pub static Example: FC<()> = |cx| {
|
||||
// To fix this, call "render" method or use the "in" syntax to produce VNodes.
|
||||
// There's nothing we can do about it, sorry :/ (unless you want *really* unhygenic macros)
|
||||
{match true {
|
||||
true => rsx!(in cx, h1 {"Top text"}),
|
||||
true => rsx!(cx, h1 {"Top text"}),
|
||||
false => cx.render(rsx!( h1 {"Bottom text"}))
|
||||
}}
|
||||
|
||||
@@ -117,9 +117,9 @@ pub static Example: FC<()> = |cx| {
|
||||
|
||||
// True conditions need to be rendered (same reasons as matching)
|
||||
{if true {
|
||||
rsx!(in cx, h1 {"Top text"})
|
||||
rsx!(cx, h1 {"Top text"})
|
||||
} else {
|
||||
rsx!(in cx, h1 {"Bottom text"})
|
||||
rsx!(cx, h1 {"Bottom text"})
|
||||
}}
|
||||
|
||||
// returning "None" is a bit noisy... but rare in practice
|
||||
|
||||
@@ -15,8 +15,8 @@ static App: FC<()> = |cx| {
|
||||
let (selection, set_selection) = use_state(cx, || None as Option<usize>).classic();
|
||||
|
||||
let body = match selection {
|
||||
Some(id) => rsx!(in cx, ReferenceItem { selected: *id }),
|
||||
None => rsx!(in cx, div { "Select an concept to explore" }),
|
||||
Some(id) => rsx!(cx, ReferenceItem { selected: *id }),
|
||||
None => rsx!(cx, div { "Select an concept to explore" }),
|
||||
};
|
||||
|
||||
cx.render(rsx! {
|
||||
|
||||
Reference in new issue
Block a user