chore: rename ctx to cx
This commit is contained in:
1 parent
23c14078bb
commit
81382e7044
99 files changed
+789
-664
No files matched your search
@@ -82,8 +82,8 @@ fn main() {
|
||||
dioxus::web::start(App)
|
||||
}
|
||||
|
||||
fn App(ctx: Context<()>) -> VNode {
|
||||
ctx.render(rsx! {
|
||||
fn App(cx: Context<()>) -> VNode {
|
||||
cx.render(rsx! {
|
||||
div { "Hello, world!" }
|
||||
})
|
||||
}
|
||||
@@ -108,8 +108,8 @@ fn main() {
|
||||
Finally, our app. Every component in Dioxus is a function that takes in a `Context` object and returns a `VNode`.
|
||||
|
||||
```rust
|
||||
fn App(ctx: Context<()>) -> VNode {
|
||||
ctx.render(rsx! {
|
||||
fn App(cx: Context<()>) -> VNode {
|
||||
cx.render(rsx! {
|
||||
div { "Hello, world!" }
|
||||
})
|
||||
};
|
||||
@@ -119,7 +119,7 @@ In React, you'll save data between renders with hooks. However, hooks rely on gl
|
||||
|
||||
Next, we're greeted with the `rsx!` macro. This lets us add a custom DSL for declaratively building the structure of our app. The semantics of this macro are similar to that of JSX and HTML, though with a familiar Rust-y interface. The `html!` macro is also available for writing components with a JSX/HTML syntax.
|
||||
|
||||
The `rsx!` macro is lazy: it does not immediately produce elements or allocates, but rather builds a closure which can be rendered with `ctx.render`.
|
||||
The `rsx!` macro is lazy: it does not immediately produce elements or allocates, but rather builds a closure which can be rendered with `cx.render`.
|
||||
|
||||
Now, let's launch our app in a development server:
|
||||
|
||||
@@ -135,7 +135,7 @@ If we wanted to golf a bit, we can shrink our hello-world even smaller:
|
||||
|
||||
```rust
|
||||
fn main() {
|
||||
dioxus::web::start(|ctx| ctx.render(diouxs::rsx!( div { "Hello, World!" } ))
|
||||
dioxus::web::start(|cx| cx.render(diouxs::rsx!( div { "Hello, World!" } ))
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ You'll want to write RSX where you can, and in a future release we'll have a too
|
||||
|
||||
```rust
|
||||
#[fc]
|
||||
fn Example(ctx: Context, name: &str, pending: bool, count: i32 ) -> VNode {
|
||||
ctx.render(html! {
|
||||
fn Example(cx: Context, name: &str, pending: bool, count: i32 ) -> VNode {
|
||||
cx.render(html! {
|
||||
<div>
|
||||
<p> "Hello, {name}!" </p>
|
||||
<p> "Status: {pending}!" </p>
|
||||
@@ -33,8 +33,8 @@ It's also a bit easier on the eyes 🙂.
|
||||
|
||||
```rust
|
||||
#[fc]
|
||||
fn Example(ctx: Context, name: &str, pending: bool, count: i32 ) -> VNode {
|
||||
ctx.render(rsx! {
|
||||
fn Example(cx: Context, name: &str, pending: bool, count: i32 ) -> VNode {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
p {"Hello, {name}!"}
|
||||
p {"Status: {pending}!"}
|
||||
@@ -58,7 +58,7 @@ Commas are entirely optional, but might be useful to delineate between elements
|
||||
The `render` function provides an **extremely efficient** allocator for VNodes and text, so try not to use the `format!` macro in your components. Rust's default `ToString` methods pass through the global allocator, but all text in components is allocated inside a manually-managed Bump arena.
|
||||
|
||||
```rust
|
||||
static Example: FC<()> = |ctx| {
|
||||
static Example: FC<()> = |cx| {
|
||||
|
||||
let text = "example";
|
||||
|
||||
@@ -67,11 +67,11 @@ static Example: FC<()> = |ctx| {
|
||||
"hello"
|
||||
};
|
||||
|
||||
let user_name = use_read_async(ctx, USERNAME);
|
||||
let title = ctx.suspend(user_name, |user_name| rsx!{ h1 { "Welcome back, {user_name}" } });
|
||||
let user_name = use_read_async(cx, USERNAME);
|
||||
let title = cx.suspend(user_name, |user_name| rsx!{ h1 { "Welcome back, {user_name}" } });
|
||||
|
||||
|
||||
ctx.render(rsx!{
|
||||
cx.render(rsx!{
|
||||
div {
|
||||
h1 { "Example" },
|
||||
|
||||
@@ -125,9 +125,9 @@ static Example: FC<()> = |ctx| {
|
||||
// rsx! is lazy, and the underlying closures cannot have the same type
|
||||
// Rendering produces the VNode type
|
||||
{match rand::gen_range::<i32>(1..3) {
|
||||
1 => rsx!(in ctx, h1 { "big" })
|
||||
2 => rsx!(in ctx, h2 { "medium" })
|
||||
_ => rsx!(in ctx, h3 { "small" })
|
||||
1 => rsx!(in cx, h1 { "big" })
|
||||
2 => rsx!(in cx, h2 { "medium" })
|
||||
_ => rsx!(in cx, h3 { "small" })
|
||||
}}
|
||||
|
||||
// Optionals
|
||||
@@ -138,12 +138,12 @@ static Example: FC<()> = |ctx| {
|
||||
|
||||
// Child nodes
|
||||
// Returns &[VNode]
|
||||
{ctx.children()}
|
||||
{cx.children()}
|
||||
|
||||
// Duplicating nodes
|
||||
// Clones the nodes by reference, so they are literally identical
|
||||
{{
|
||||
let node = rsx!(in ctx, h1{ "TopNode" });
|
||||
let node = rsx!(in cx, h1{ "TopNode" });
|
||||
(0..10).map(|_| node.clone())
|
||||
}}
|
||||
|
||||
|
||||
Reference in new issue
Block a user