feat: mvoe away from compound context
This commit is contained in:
1 parent
bfdcb20437
commit
a2c7d17b05
103 files changed
+309
-293
No files matched your search
@@ -16,10 +16,10 @@ use dioxus::prelude::*;
|
||||
pub struct MyProps {
|
||||
should_show: bool,
|
||||
}
|
||||
pub static Example0: FC<MyProps> = |cx| {
|
||||
pub static Example0: FC<MyProps> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
{cx.should_show.then(|| rsx!{
|
||||
{props.should_show.then(|| rsx!{
|
||||
h1 { "showing the title!" }
|
||||
})}
|
||||
}
|
||||
@@ -39,17 +39,17 @@ pub static Example0: FC<MyProps> = |cx| {
|
||||
pub struct MyProps1 {
|
||||
should_show: bool,
|
||||
}
|
||||
pub static Example1: FC<MyProps1> = |cx| {
|
||||
pub static Example1: FC<MyProps1> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
// With matching
|
||||
{match cx.should_show {
|
||||
{match props.should_show {
|
||||
true => cx.render(rsx!(div {"it is true!"})),
|
||||
false => rsx!(cx, div {"it is false!"}),
|
||||
}}
|
||||
|
||||
// or with just regular conditions
|
||||
{if cx.should_show {
|
||||
{if props.should_show {
|
||||
rsx!(cx, div {"it is true!"})
|
||||
} else {
|
||||
rsx!(cx, div {"it is false!"})
|
||||
@@ -57,7 +57,7 @@ pub static Example1: FC<MyProps1> = |cx| {
|
||||
|
||||
// or with optional chaining
|
||||
{
|
||||
cx.should_show
|
||||
props.should_show
|
||||
.then(|| rsx!(cx, div {"it is false!"}))
|
||||
.unwrap_or_else(|| rsx!(cx, div {"it is false!"}))
|
||||
}
|
||||
@@ -77,10 +77,10 @@ pub enum Color {
|
||||
pub struct MyProps2 {
|
||||
color: Color,
|
||||
}
|
||||
pub static Example2: FC<MyProps2> = |cx| {
|
||||
pub static Example2: FC<MyProps2> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
{match cx.color {
|
||||
{match props.color {
|
||||
Color::Green => rsx!(cx, div {"it is Green!"}),
|
||||
Color::Yellow => rsx!(cx, div {"it is Yellow!"}),
|
||||
Color::Red => rsx!(cx, div {"it is Red!"}),
|
||||
@@ -89,7 +89,7 @@ pub static Example2: FC<MyProps2> = |cx| {
|
||||
})
|
||||
};
|
||||
|
||||
pub static Example: FC<()> = |cx| {
|
||||
pub static Example: FC<()> = |cx, props| {
|
||||
let should_show = use_state(cx, || false);
|
||||
let mut color_index = use_state(cx, || 0);
|
||||
let color = match *color_index % 2 {
|
||||
|
||||
Reference in new issue
Block a user