diff --git a/README.md b/README.md
index 04d01dead..641f5a8b8 100644
--- a/README.md
+++ b/README.md
@@ -50,6 +50,14 @@
+
+
Dioxus is a portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust.
@@ -108,7 +116,7 @@ cargo run --example EXAMPLE
| [](https://github.com/DioxusLabs/example-projects/blob/master/file-explorer) | [](https://github.com/DioxusLabs/example-projects/blob/master/wifi-scanner) | [](https://github.com/DioxusLabs/example-projects/blob/master/todomvc) | [](https://github.com/DioxusLabs/example-projects/blob/master/ecommerce-site) |
-See the awesome-dioxus page for a curated list of content in the Dioxus Ecosystem.
+See the [awesome-dioxus](https://github.com/DioxusLabs/awesome-dioxus) page for a curated list of content in the Dioxus Ecosystem.
## Why Dioxus and why Rust?
@@ -151,7 +159,7 @@ You shouldn't use Dioxus if:
### Comparison with other Rust UI frameworks
Dioxus primarily emphasizes **developer experience** and **familiarity with React principles**.
-- [Yew](https://github.com/yewstack/yew): prefers the elm pattern instead of React-hooks, no borrowed props, no SSR.
+- [Yew](https://github.com/yewstack/yew): prefers the elm pattern instead of React-hooks, no borrowed props, supports SSR (no hydration).
- [Percy](https://github.com/chinedufn/percy): Supports SSR but less emphasis on state management and event handling.
- [Sycamore](https://github.com/sycamore-rs/sycamore): VDOM-less using fine-grained reactivity, but lacking in ergonomics.
- [Dominator](https://github.com/Pauan/rust-dominator): Signal-based zero-cost alternative, less emphasis on community and docs.
diff --git a/docs/guide/book.toml b/docs/guide/book.toml
index 48ead3936..eabbe6f2b 100644
--- a/docs/guide/book.toml
+++ b/docs/guide/book.toml
@@ -10,8 +10,8 @@ edition = "2018"
[output.html]
mathjax-support = true
site-url = "/mdBook/"
-git-repository-url = "https://github.com/rust-lang/mdBook/tree/master/guide"
-edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}"
+git-repository-url = "https://github.com/DioxusLabs/dioxus/edit/master/docs/guide"
+edit-url-template = "https://github.com/DioxusLabs/dioxus/edit/master/docs/guide/{path}"
[output.html.playground]
editable = true
diff --git a/examples/dog_app.rs b/examples/dog_app.rs
index 3b35ae174..b2f8429ee 100644
--- a/examples/dog_app.rs
+++ b/examples/dog_app.rs
@@ -61,7 +61,7 @@ fn app(cx: Scope) -> Element {
#[inline_props]
fn Breed(cx: Scope, breed: String) -> Element {
- #[derive(serde::Deserialize)]
+ #[derive(serde::Deserialize, Debug)]
struct DogApi {
message: String,
}
@@ -72,6 +72,12 @@ fn Breed(cx: Scope, breed: String) -> Element {
reqwest::get(endpoint).await.unwrap().json::().await
});
+ let breed_name = use_state(&cx, || breed.clone());
+ if breed_name.get() != breed {
+ breed_name.set(breed.clone());
+ fut.restart();
+ }
+
cx.render(match fut.value() {
Some(Ok(resp)) => rsx! {
button {
diff --git a/examples/link.rs b/examples/link.rs
new file mode 100644
index 000000000..41b010e8d
--- /dev/null
+++ b/examples/link.rs
@@ -0,0 +1,28 @@
+use dioxus::prelude::*;
+
+fn main() {
+ dioxus::desktop::launch(app);
+}
+
+fn app(cx: Scope) -> Element {
+ cx.render(rsx! (
+ div {
+ p {
+ a {
+ href: "http://dioxuslabs.com/",
+ "default link"
+ }
+ }
+ p {
+ a {
+ href: "http://dioxuslabs.com/",
+ prevent_default: "onclick",
+ onclick: |_| {
+ println!("Hello Dioxus");
+ },
+ "custom event link",
+ }
+ }
+ }
+ ))
+}
diff --git a/examples/optional_props.rs b/examples/optional_props.rs
index 47ccbeac0..9485a2aeb 100644
--- a/examples/optional_props.rs
+++ b/examples/optional_props.rs
@@ -1,3 +1,5 @@
+#![allow(non_snake_case)]
+
//! Example: README.md showcase
//!
//! The example from the README.md.
@@ -14,6 +16,7 @@ fn app(cx: Scope) -> Element {
a: "asd".to_string(),
c: Some("asd".to_string()),
d: "asd".to_string(),
+ e: "asd".to_string(),
}
})
}
@@ -30,8 +33,19 @@ struct ButtonProps {
#[props(default, strip_option)]
d: Option,
+
+ #[props(optional)]
+ e: Option,
}
fn Button(cx: Scope) -> Element {
- todo!()
+ cx.render(rsx! {
+ button {
+ "{cx.props.a}"
+ "{cx.props.b:?}"
+ "{cx.props.c:?}"
+ "{cx.props.d:?}"
+ "{cx.props.e:?}"
+ }
+ })
}
diff --git a/examples/router.rs b/examples/router.rs
index bd6d51881..121514423 100644
--- a/examples/router.rs
+++ b/examples/router.rs
@@ -2,6 +2,7 @@
use dioxus::prelude::*;
use dioxus::router::{Link, Route, Router};
+use serde::Deserialize;
fn main() {
dioxus::desktop::launch(app);
@@ -30,7 +31,7 @@ fn app(cx: Scope) -> Element {
}
fn BlogPost(cx: Scope) -> Element {
- let post = dioxus::router::use_route(&cx).last_segment()?;
+ let post = dioxus::router::use_route(&cx).last_segment();
cx.render(rsx! {
div {
@@ -40,9 +41,14 @@ fn BlogPost(cx: Scope) -> Element {
})
}
+#[derive(Deserialize)]
+struct Query {
+ bold: bool,
+}
+
fn User(cx: Scope) -> Element {
- let post = dioxus::router::use_route(&cx).last_segment()?;
- let bold = dioxus::router::use_route(&cx).param::("bold");
+ let post = dioxus::router::use_route(&cx).last_segment();
+ let query = dioxus::router::use_route(&cx).query::();
cx.render(rsx! {
div {
diff --git a/notes/README/ZH_CN.md b/notes/README/ZH_CN.md
new file mode 100644
index 000000000..614774595
--- /dev/null
+++ b/notes/README/ZH_CN.md
@@ -0,0 +1,168 @@
+
+
🌗🚀 Dioxus
+
+ Frontend that scales.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Dioxus 是一个可移植、高性能的框架,用于在 Rust 中构建跨平台的用户界面。
+
+```rust
+fn app(cx: Scope) -> Element {
+ let mut count = use_state(&cx, || 0);
+
+ cx.render(rsx!(
+ h1 { "High-Five counter: {count}" }
+ button { onclick: move |_| count += 1, "Up high!" }
+ button { onclick: move |_| count -= 1, "Down low!" }
+ ))
+}
+```
+
+Dioxus 可用于制作 网页程序、桌面应用、静态站点、移动端应用。
+
+Dioxus 为不同的平台都提供了很好的开发文档。
+
+如果你会使用 React ,那 Dioxus 对你来说会很简单。
+
+### 项目特点:
+- 对桌面应用的原生支持。
+- 强大的状态管理工具。
+- 支持所有 HTML 标签,监听器和事件。
+- 超高的内存使用率,稳定的组件分配器。
+- 多通道异步调度器,超强的异步支持。
+- 更多信息请查阅: [版本发布文档](https://dioxuslabs.com/blog/introducing-dioxus/).
+
+### 示例
+
+本项目中的所有例子都是 `桌面应用` 程序,请使用 `cargo run --example XYZ` 运行这些例子。
+
+```
+cargo run --example EXAMPLE
+```
+
+## 进入学习
+
+
+
+
+## Dioxus 项目
+
+| 文件浏览器 (桌面应用) | WiFi 扫描器 (桌面应用) | Todo管理 (所有平台) | 商城系统 (SSR/liveview) |
+| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| [](https://github.com/DioxusLabs/example-projects/blob/master/file-explorer) | [](https://github.com/DioxusLabs/example-projects/blob/master/wifi-scanner) | [](https://github.com/DioxusLabs/example-projects/blob/master/todomvc) | [](https://github.com/DioxusLabs/example-projects/blob/master/ecommerce-site) |
+
+
+查看 [awesome-dioxus](https://github.com/DioxusLabs/awesome-dioxus) 查看更多有趣(~~NiuBi~~)的项目!
+
+## 为什么使用 Dioxus 和 Rust ?
+
+TypeScript 是一个不错的 JavaScript 拓展集,但它仍然算是 JavaScript。
+
+TS 代码运行效率不高,而且有大量的配置项。
+
+相比之下,Dioxus 使用 Rust 编写将大大的提高效能。
+
+使用 Rust 开发,我们能获得:
+
+- 静态类型支持。
+- 变量默认不变性。
+- 简单直观的模块系统。
+- 内部集成的文档系统。
+- 先进的模式匹配系统。
+- 简洁、高效、强大的迭代器。
+- 内置的 单元测试 / 集成测试。
+- 优秀的异常处理系统。
+- 强大且健全的标准库。
+- 灵活的 `宏` 系统。
+- 使用 `crates.io` 管理包。
+
+Dioxus 能为开发者提供的:
+
+- 安全使用数据结构。
+- 安全的错误处理结果。
+- 拥有原生移动端的性能。
+- 直接访问系统的IO层。
+
+Dioxus 使 Rust 应用程序的编写速度和 React 应用程序一样快,但提供了更多的健壮性,让团队能在更短的时间内做出强大功能。
+
+### 不建议使用 Dioxus 的情况?
+
+您不该在这些情况下使用 Dioxus :
+
+- 您不喜欢类似 React 的开发风格。
+- 您需要一个 `no-std` 的渲染器。
+- 您希望应用运行在 `不支持 Wasm 或 asm.js` 的浏览器。
+- 您需要一个 `Send + Sync` UI 解决方案(目前不支持)。
+
+
+## 协议
+
+这个项目使用 [MIT 协议].
+
+[MIT 协议]: https://github.com/dioxuslabs/dioxus/blob/master/LICENSE
diff --git a/packages/core-macro/src/props/mod.rs b/packages/core-macro/src/props/mod.rs
index f5443272b..d569e711a 100644
--- a/packages/core-macro/src/props/mod.rs
+++ b/packages/core-macro/src/props/mod.rs
@@ -364,6 +364,14 @@ mod field_info {
Some(syn::parse(quote!(Default::default()).into()).unwrap());
Ok(())
}
+
+ "optional" => {
+ self.default =
+ Some(syn::parse(quote!(Default::default()).into()).unwrap());
+ self.strip_option = true;
+ Ok(())
+ }
+
_ => {
macro_rules! handle_fields {
( $( $flag:expr, $field:ident, $already:expr; )* ) => {
diff --git a/packages/core/src/nodes.rs b/packages/core/src/nodes.rs
index d662b4998..80de92917 100644
--- a/packages/core/src/nodes.rs
+++ b/packages/core/src/nodes.rs
@@ -351,31 +351,25 @@ type ExternalListenerCallback<'bump, T> = BumpBox<'bump, dyn FnMut(T) + 'bump>;
/// }
///
/// ```
+#[derive(Default)]
pub struct EventHandler<'bump, T = ()> {
- pub callback: &'bump RefCell