Feat: some docs

This commit is contained in:
Jonathan Kelley committed 2021-06-02 11:07:30 -04:00
1 parent 508c560320
commit 1919f88f03
10 files changed
+179 -182

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
# A Simple Component
```rust
#[derive(PartialEq, Properties)]
struct Props { name: &'static str }
static HelloMessage: FC<Props> = |ctx| {
ctx.render(rsx!{
div { "Hello {ctx.props.name}" }
})
}
```
# Any syntax you like
Choose from a close-to-html syntax or the standard rsx! syntax
```rust
static HelloMessage: FC<()> = |ctx| {
ctx.render(html!{
<div> Hello World! </div>
})
}
```
# A Stateful Component
Store state with hooks!
```rust
enum LightState {
Green
Yellow,
Red,
}
static HelloMessage: FC<()> = |ctx| {
let (color, set_color) = use_state(ctx, || LightState::Green);
let title = match color {
Green => "Green means go",
Yellow => "Yellow means slow down",
Red => "Red means stop",
};
ctx.render(rsx!{
h1 {"{title}"}
button { "tick"
onclick: move |_| set_color(match color {
Green => Yellow,
Yellow => Red,
Red => Green,
})
}
})
}
```