fix: readme and examples syntax

This commit is contained in:
Jonathan Kelley committed 2021-12-28 23:48:25 -05:00
1 parent f24aae8787
commit 3dc0e59876
102 files changed
+213 -1222

No files matched your search

@@ -3,7 +3,7 @@
Yew subscriptions are used to schedule update for components into the future. The `Context` object can create subscriptions:
```rust
fn Component(cx: Component<()>) -> DomTree {
fn Component(cx: Component) -> DomTree {
let update = cx.schedule();
// Now, when the subscription is called, the component will be re-evaluated
+2 -2
View File
@@ -21,9 +21,9 @@ fn test() -> DomTree {
}
}
static TestComponent: Component<()> = |cx| html!{<div>"Hello world"</div>};
static TestComponent: Component = |cx| html!{<div>"Hello world"</div>};
static TestComponent: Component<()> = |cx|{
static TestComponent: Component = |cx|{
let g = "BLAH";
html! {
<div> "Hello world" </div>
+3 -3
View File
@@ -96,7 +96,7 @@ Sometimes you want a signal to propagate across your app, either through far-awa
```rust
const TITLE: Atom<String> = || "".to_string();
const Provider: Component<()> = |cx|{
const Provider: Component = |cx|{
let title = use_signal(&cx, &TITLE);
rsx!(cx, input { value: title })
};
@@ -105,7 +105,7 @@ const Provider: Component<()> = |cx|{
If we use the `TITLE` atom in another component, we can cause updates to flow between components without calling render or diffing either component trees:
```rust
const Receiver: Component<()> = |cx|{
const Receiver: Component = |cx|{
let title = use_signal(&cx, &TITLE);
log::info!("This will only be called once!");
rsx!(cx,
@@ -132,7 +132,7 @@ Dioxus automatically understands how to use your signals when mixed with iterato
```rust
const DICT: AtomFamily<String, String> = |_| {};
const List: Component<()> = |cx|{
const List: Component = |cx|{
let dict = use_signal(&cx, &DICT);
cx.render(rsx!(
ul {
@@ -83,7 +83,7 @@ fn App(cx: Scope)-> Element {
This syntax even enables us to write a one-line component:
```rust
static App: Component<()> = |cx| rsx!(cx, "hello world!");
static App: Component = |cx| rsx!(cx, "hello world!");
```
Alternatively, for match statements, we can just return the builder itself and pass it into a final, single call to `cx.render`:
+1 -1
View File
@@ -4,7 +4,7 @@
Astute observers might have noticed that `Element` is actually a type alias for `Option<VNode>`. You don't need to know what a `VNode` is, but it's important to recognize that we could actually return nothing at all:
```rust
fn App((cx, props): Component<()>) -> Element {
fn App((cx, props): Component) -> Element {
None
}
```
@@ -25,7 +25,7 @@ fn main() {
dioxus::desktop::launch(App);
}
fn App((cx, props): Component<()>) -> Element {}
fn App((cx, props): Component) -> Element {}
#[derive(PartialEq, Props)]
struct PostProps{}
@@ -92,7 +92,7 @@ fn main() {
mod post;
fn App((cx, props): Component<()>) -> Element {
fn App((cx, props): Component) -> Element {
cx.render(rsx!{
post::Post {
id: Uuid::new_v4(),
@@ -191,7 +191,7 @@ fn main() {
mod post;
fn App((cx, props): Component<()>) -> Element {
fn App((cx, props): Component) -> Element {
cx.render(rsx!{
post::Post {
id: Uuid::new_v4(),
+1 -1
View File
@@ -135,7 +135,7 @@ fn App(cx: Scope) -> Element {
Writing `fn App(cx: Scope) -> Element {` might become tedious. Rust will also let you write functions as static closures, but these types of Components cannot have props that borrow data.
```rust
static App: Component<()> = |cx| cx.render(rsx!(div { "Hello, world!" }));
static App: Component = |cx| cx.render(rsx!(div { "Hello, world!" }));
```
### What is this `Context` object?