Proofread & rephrase chapters 1-5 for readability
This commit is contained in:
1 parent
82b0e6c8d6
commit
6727de447b
6 files changed
+76
-128
No files matched your search
@@ -56,7 +56,7 @@ With the default configuration, any Element defined within the `dioxus-html` cra
|
||||
|
||||
## Text Elements
|
||||
|
||||
Dioxus also supports a special type of Element: Text. Text Elements do not accept children, but rather just string literals denoted with double quotes.
|
||||
Dioxus also supports a special type of Element: Text. Text Elements do not accept children, just a string literal denoted by double quotes.
|
||||
|
||||
```rust
|
||||
rsx! (
|
||||
@@ -74,20 +74,20 @@ rsx! (
|
||||
)
|
||||
```
|
||||
|
||||
Text can also be formatted with any value that implements `Display`. We use [f-string formatting](https://docs.rs/fstrings/0.2.3/fstrings/) - a "coming soon" feature for stable Rust that is familiar for Python and JavaScript users:
|
||||
Text can also be formatted with any value that implements `Display`. We use the same syntax as Rust [format strings](https://www.rustnote.com/blog/format_strings.html) – which will already be familiar for Python and JavaScript users:
|
||||
|
||||
```rust
|
||||
let name = "Bob";
|
||||
rsx! ( "hello {name}" )
|
||||
```
|
||||
|
||||
Unfortunately, you cannot drop in arbitrary expressions directly into the string literal. In the cases where we need to compute a complex value, we'll want to use `format_args!` directly. Due to specifics of how the `rsx!` macro (we'll cover later), our call to `format_args` must be contained within square braces.
|
||||
Unfortunately, you cannot drop in arbitrary expressions directly into the string literal. In the cases where we need to compute a complex value, we'll want to use `format_args!` directly. Due to specifics of the `rsx!` macro (which we'll cover later), our call to `format_args` must be contained within square braces.
|
||||
|
||||
```rust
|
||||
rsx!( {format_args!("Hello {}", if enabled { "Jack" } else { "Bob" } )] )
|
||||
rsx!( [format_args!("Hello {}", if enabled { "Jack" } else { "Bob" } )] )
|
||||
```
|
||||
|
||||
Alternatively, `&str` can be included directly, though it must be inside of square braces:
|
||||
Alternatively, `&str` can be included directly, though it must also be inside square braces:
|
||||
|
||||
```rust
|
||||
rsx!( "Hello ", [if enabled { "Jack" } else { "Bob" }] )
|
||||
@@ -104,7 +104,7 @@ rsx! ( "hello {name}" )
|
||||
|
||||
## Attributes
|
||||
|
||||
Every Element in your User Interface will have some sort of properties that the renderer will use when drawing to the screen. These might inform the renderer if the component should be hidden, what its background color should be, or to give it a specific name or ID.
|
||||
Every Element in your user interface will have some sort of properties that the renderer will use when drawing to the screen. These might inform the renderer if the component should be hidden, what its background color should be, or to give it a specific name or ID.
|
||||
|
||||
To do this, we use the familiar struct-style syntax that Rust provides:
|
||||
|
||||
@@ -123,7 +123,7 @@ Each field is defined as a method on the element in the `dioxus-html` crate. Thi
|
||||
1) file an issue if the attribute _should_ be enabled
|
||||
2) add a custom attribute on-the-fly
|
||||
|
||||
To use custom attributes, simply put the attribute name in quotes followed by a colon:
|
||||
To use custom attributes, simply put the attribute name in quotes:
|
||||
|
||||
```rust
|
||||
rsx!(
|
||||
|
||||
Reference in new issue
Block a user