dioxus/README.md

205 lines
9.5 KiB
Markdown
Raw Normal View History

2021-01-16 15:31:17 +00:00
<div align="center">
2022-02-05 01:57:32 +00:00
<h1>Dioxus</h1>
2021-01-16 15:31:17 +00:00
<p>
2021-03-02 06:47:27 +00:00
<strong>Frontend that scales.</strong>
2021-01-16 15:31:17 +00:00
</p>
</div>
2021-07-12 16:20:58 +00:00
<div align="center">
<!-- Crates version -->
2021-09-07 22:25:57 +00:00
<a href="https://crates.io/crates/dioxus">
<img src="https://img.shields.io/crates/v/dioxus.svg?style=flat-square"
2021-07-12 16:20:58 +00:00
alt="Crates.io version" />
</a>
<!-- Downloads -->
2021-09-07 22:25:57 +00:00
<a href="https://crates.io/crates/dioxus">
<img src="https://img.shields.io/crates/d/dioxus.svg?style=flat-square"
2021-07-12 16:20:58 +00:00
alt="Download" />
</a>
<!-- docs -->
2021-09-07 22:25:57 +00:00
<a href="https://docs.rs/dioxus">
2021-07-12 16:20:58 +00:00
<img src="https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square"
alt="docs.rs docs" />
</a>
<!-- CI -->
<a href="https://github.com/jkelleyrtp/dioxus/actions">
2021-12-29 04:48:25 +00:00
<img src="https://github.com/dioxuslabs/dioxus/actions/workflows/main.yml/badge.svg"
2021-07-12 16:20:58 +00:00
alt="CI status" />
</a>
<!--Awesome -->
<a href="https://github.com/dioxuslabs/awesome-dioxus">
<img src="https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg" alt="Awesome Page" />
</a>
<!-- Discord -->
<a href="https://discord.gg/XgGxMSkvUM">
2022-01-25 18:17:43 +00:00
<img src="https://img.shields.io/discord/899851952891002890.svg?logo=discord&style=flat-square" alt="Discord Link" />
2021-07-12 16:20:58 +00:00
</a>
</div>
2022-01-25 18:17:43 +00:00
2021-07-12 16:20:58 +00:00
<div align="center">
<h3>
2021-12-29 04:48:25 +00:00
<a href="https://dioxuslabs.com"> Website </a>
2021-07-12 16:22:08 +00:00
<span> | </span>
<a href="https://dioxuslabs.com/guide"> Guide </a>
<span> | </span>
<a href="https://github.com/DioxusLabs/example-projects"> Examples </a>
2021-07-12 16:20:58 +00:00
</h3>
</div>
2022-01-13 04:16:17 +00:00
<div align="center">
<h4>
<a href="https://github.com/DioxusLabs/dioxus/blob/master/README.md"> English </a>
<span> | </span>
2022-01-13 14:30:18 +00:00
<a href="https://github.com/DioxusLabs/dioxus/blob/master/notes/README/ZH_CN.md"> 中文 </a>
2022-01-13 04:16:17 +00:00
</h3>
</div>
2021-07-12 16:20:58 +00:00
<br/>
2021-12-29 04:48:25 +00:00
Dioxus is a portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust.
```rust
2021-12-29 04:20:01 +00:00
fn app(cx: Scope) -> Element {
2022-01-27 20:53:06 +00:00
let (count, set_count) = use_state(&cx, || 0);
2021-02-25 23:44:00 +00:00
2021-09-20 20:49:36 +00:00
cx.render(rsx!(
2021-07-11 23:31:07 +00:00
h1 { "High-Five counter: {count}" }
2022-01-27 20:53:06 +00:00
button { onclick: move |_| set_count(count + 1), "Up high!" }
button { onclick: move |_| set_count(count - 1), "Down low!" }
2021-09-20 20:49:36 +00:00
))
}
```
2021-09-20 20:49:36 +00:00
Dioxus can be used to deliver webapps, desktop apps, static sites, liveview apps, mobile apps (WIP), and more. At its core, Dioxus is entirely renderer agnostic and has great documentation for creating new renderers for any platform.
If you know React, then you already know Dioxus.
### Unique features:
2021-10-19 16:09:23 +00:00
- Desktop apps running natively (no Electron!) in less than 10 lines of code.
2021-12-01 03:48:05 +00:00
- Incredibly ergonomic and powerful state management.
2021-12-29 04:48:25 +00:00
- Comprehensive inline documentation - hover and guides for all HTML elements, listeners, and events.
2021-12-01 03:48:05 +00:00
- Extremely memory efficient - 0 global allocations for steady-state components.
2021-12-29 04:48:25 +00:00
- Multi-channel asynchronous scheduler for first-class async support.
- And more! Read the [full release post](https://dioxuslabs.com/blog/introducing-dioxus/).
### Examples
All examples in this repo are desktop apps. To run an example, simply clone this repo and use `cargo run --example XYZ`
```
cargo run --example EXAMPLE
```
2021-03-01 05:16:48 +00:00
## Get Started with...
2021-02-08 22:09:21 +00:00
<table style="width:100%" align="center">
<tr >
2022-01-03 15:20:14 +00:00
<th><a href="https://dioxuslabs.com/guide/">Tutorial</a></th>
<th><a href="https://dioxuslabs.com/reference/web">Web</a></th>
<th><a href="https://dioxuslabs.com/reference/desktop/">Desktop</a></th>
<th><a href="https://dioxuslabs.com/reference/ssr/">SSR</a></th>
<th><a href="https://dioxuslabs.com/reference/mobile/">Mobile</a></th>
<th><a href="https://dioxuslabs.com/guide/concepts/managing_state.html">State</a></th>
2021-02-08 22:05:58 +00:00
<tr>
</table>
2021-09-07 22:32:47 +00:00
## Example Projects:
2021-09-20 20:49:36 +00:00
2022-01-03 16:37:50 +00:00
| File Navigator (Desktop) | WiFi scanner (Desktop) | TodoMVC (All platforms) | E-commerce w/ Tailwind (SSR/LiveView) |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [![File Explorer](https://github.com/DioxusLabs/example-projects/raw/master/file-explorer/image.png)](https://github.com/DioxusLabs/example-projects/blob/master/file-explorer) | [![Wifi Scanner Demo](https://github.com/DioxusLabs/example-projects/raw/master/wifi-scanner/demo_small.png)](https://github.com/DioxusLabs/example-projects/blob/master/wifi-scanner) | [![TodoMVC example](https://github.com/DioxusLabs/example-projects/raw/master/todomvc/example.png)](https://github.com/DioxusLabs/example-projects/blob/master/todomvc) | [![E-commerce Example](https://github.com/DioxusLabs/example-projects/raw/master/ecommerce-site/demo.png)](https://github.com/DioxusLabs/example-projects/blob/master/ecommerce-site) |
2021-12-15 03:59:34 +00:00
2021-09-20 20:49:36 +00:00
2022-01-13 04:30:05 +00:00
See the [awesome-dioxus](https://github.com/DioxusLabs/awesome-dioxus) page for a curated list of content in the Dioxus Ecosystem.
2021-09-10 00:58:48 +00:00
2021-12-01 03:48:05 +00:00
## Why Dioxus and why Rust?
TypeScript is a fantastic addition to JavaScript, but it's still fundamentally JavaScript. TS code runs slightly slower, has tons of configuration options, and not every package is properly typed.
In contrast, Dioxus is written in Rust - which is almost like "TypeScript on steroids".
2021-12-01 03:48:05 +00:00
By using Rust, we gain:
- Static types for *every* library
- Immutability by default
- A simple and intuitive module system
- Integrated documentation (`go to source` _actually goes to source_)
- Advanced pattern matching
- Clean, efficient, composable iterators
- Inline built-in unit/integration testing
- Best-in-class error handling
2021-12-01 03:50:26 +00:00
- Powerful and sane standard library
2021-12-01 03:48:05 +00:00
- Flexible macro system
- Access to `crates.io`
Specifically, Dioxus provides us many other assurances:
- Proper use of immutable data structures
- Guaranteed error handling (so you can sleep easy at night not worrying about `cannot read property of undefined`)
2021-12-01 03:48:05 +00:00
- Native performance on mobile
- Direct access to system IO
And much more. Dioxus makes Rust apps just as fast to write as React apps, but affords more robustness, giving your frontend team greater confidence in making big changes in shorter time.
2021-12-01 03:48:05 +00:00
2022-01-26 05:40:51 +00:00
## Why NOT Dioxus?
2021-12-01 03:48:05 +00:00
You shouldn't use Dioxus if:
2021-12-01 03:50:26 +00:00
2021-12-01 03:48:05 +00:00
- You don't like the React Hooks approach to frontend
- You need a no-std renderer
- You want to support browsers where Wasm or asm.js are not supported.
- You need a Send+Sync UI solution (Dioxus is not currently thread-safe)
2021-06-24 15:09:38 +00:00
2022-01-26 05:40:51 +00:00
## Comparison with other Rust UI frameworks
Dioxus primarily emphasizes **developer experience** and **familiarity with React principles**.
2022-01-13 16:25:18 +00:00
- [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 with 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.
2022-01-22 21:19:52 +00:00
- [Azul](https://azul.rs): Fully native HTML/CSS renderer for desktop applications, no support for web/ssr
2022-01-26 05:40:01 +00:00
## Parity with React & Roadmap
2021-09-20 16:32:21 +00:00
2022-01-26 05:40:01 +00:00
Dioxus is heavily inspired by React, but we want your transition to feel like an upgrade. Dioxus is _most_ of the way there, but missing a few key features. These include:
- Portals
- Suspense integration with SSR
- Server Components / Bundle Splitting / Lazy
Dioxus is unique in the Rust ecosystem in that it supports:
- Components with props that borrow from their parent
- Server-side-rendering with client-side hydration
- Support for desktop applications
For more information on what features are currently available and the roadmap for the future, be sure to check out [the guide](https://dioxuslabs.com/guide/).
## Projects in the ecosystem
Want to jump in and help build the future of Rust frontend? There's plenty of places where your contributions can make a huge difference:
- [TUI renderer](https://github.com/dioxusLabs/rink)
- [CLI Tooling](https://github.com/dioxusLabs/cli)
- [Documentation and Example Projects](https://github.com/dioxusLabs/docsite)
- LiveView and Web Server
- Asset System
2021-11-12 21:06:33 +00:00
2021-09-20 16:36:43 +00:00
## License
This project is licensed under the [MIT license].
2021-12-29 04:48:25 +00:00
[MIT license]: https://github.com/dioxuslabs/dioxus/blob/master/LICENSE
2021-09-20 16:36:43 +00:00
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
2021-12-15 03:59:34 +00:00
for inclusion in Dioxus by you, shall be licensed as MIT, without any additional
2021-09-20 16:36:43 +00:00
terms or conditions.