Skip to main content

Crate dioxus

Crate dioxus 

Source
Expand description

Build for web, desktop, and mobile, and more with a single codebase. Zero-config setup, integrated hot-reloading, and signals-based state management. Add backend functionality with Server Functions and bundle with our CLI.

use dioxus::prelude::*;

fn main() {
    dioxus::launch(app);
}

fn app() -> Element {
    let mut count = use_signal(|| 0);

    rsx! {
        h1 { "High-Five counter: {count}" }
        button { onclick: move |_| count += 1, "Up high!" }
        button { onclick: move |_| count -= 1, "Down low!" }
    }
}

§⭐️ Unique features

  • Cross-platform apps in three lines of code (web, desktop, mobile, server, and more)
  • Ergonomic state management combines the best of React, Solid, and Svelte
  • Built-in featureful, type-safe, fullstack web framework
  • Integrated bundler for deploying to the web, macOS, Linux, and Windows
  • Subsecond Rust hot-patching and asset hot-reloading
  • And more! Take a tour of Dioxus.

§Quick start

Grab the Dioxus CLI (dx) and spin up a new app in seconds:

# install the dioxus-cli
curl -fsSL https://dioxuslabs.com/install.sh | bash

# create a new app, following the template instructions
dx new my-app && cd my-app

# and then serve on `--web, --desktop, --ios, or --android`
dx serve --desktop

§Guides

This overview doesn’t cover everything. Make sure to check out:

§Instant hot-reloading

With one command, dx serve and your app is running. Edit your markup, styles, and see changes in milliseconds. Use our experimental dx serve --hotpatch to update Rust code in real time.

§Build Beautiful Apps

Dioxus apps are styled with HTML and CSS. Use the built-in TailwindCSS support or load your favorite CSS library. Easily call into native code (objective-c, JNI, Web-Sys) for a perfect native touch.

§Truly fullstack applications

Dioxus deeply integrates with axum to provide powerful fullstack capabilities for both clients and servers. Pick from a wide array of built-in batteries like WebSockets, SSE, Streaming, File Upload/Download, Server-Side-Rendering, Forms, Middleware, and Hot-Reload, or go fully custom and integrate your existing axum backend.

§Experimental Native Renderer

Render using web-sys, webview, server-side-rendering, liveview, or even with our experimental WGPU-based renderer. Embed Dioxus in Bevy, WGPU, or even run on embedded Linux!

§First-party primitive components

Get started quickly with a complete set of primitives modeled after shadcn/ui and Radix-Primitives.

§First-class Android and iOS support

Dioxus is the fastest way to build native mobile apps with Rust. Simply run dx serve --platform android and your app is running in an emulator or on device in seconds. Call directly into JNI and Native APIs.

§Bundle for web, desktop, and mobile

Simply run dx bundle and your app will be built and bundled with maximization optimizations. On the web, take advantage of .avif generation, .wasm compression, minification, and more. Build WebApps weighing less than 50kb and desktop/mobile apps less than 5mb.

§Fantastic documentation

We’ve put a ton of effort into building clean, readable, and comprehensive documentation. All html elements and listeners are documented with MDN docs, and our Docs runs continuous integration with Dioxus itself to ensure that the docs are always up to date. Check out the Dioxus website for guides, references, recipes, and more.

§Community

Dioxus is a community-driven project, with a very active Discord and GitHub community. We’re always looking for help, and we’re happy to answer questions and help you get started. Our SDK is community-run and we even have a GitHub organization for the best Dioxus crates that receive free upgrades and support.

§License

This project is licensed under either the MIT license or the Apache-2 License.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Dioxus by you, shall be licensed as MIT or Apache-2, without any additional terms or conditions.

§Dioxus Crate Features

This crate has several features that can be enabled to change the active renderer and enable various integrations:

  • signals: (default) re-exports dioxus-signals
  • macro: (default) re-exports dioxus-macro
  • html: (default) exports dioxus-html as the default elements to use in rsx
  • hooks: (default) re-exports dioxus-hooks
  • hot-reload: (default) enables hot rsx reloading in all renderers that support it
  • router: exports the router and enables any router features for the current platform
  • third-party-renderer: Just disables warnings about no active platform when no renderers are enabled
  • logger: Enable the default tracing subscriber for Dioxus apps

Platform features (the current platform determines what platform the launch() function runs):

  • fullstack: enables the fullstack platform. This must be used in combination with the web feature for wasm builds and server feature for server builds
  • desktop: enables the desktop platform
  • mobile: enables the mobile platform
  • web: enables the web platform. If the fullstack platform is enabled, this will set the fullstack platform to client mode
  • liveview: enables the liveview platform
  • server: enables the server variant of dioxus

Re-exports§

pub use dioxus_core;
pub use dioxus_core as core;
pub use dioxus_hooks as hooks;hooks
pub use dioxus_signals as signals;signals
pub use dioxus_stores as stores;signals
pub use dioxus_document as document;document
pub use dioxus_history as history;document
pub use dioxus_html as html;html
pub use dioxus_core_macro as core_macro;macro
pub use dioxus_logger as logger;logger
pub use dioxus_cli_config as cli_config;cli-config
pub use dioxus_server as server;server
pub use dioxus_devtools as devtools;devtools
pub use dioxus_web as web;web
pub use dioxus_router as router;router
pub use dioxus_fullstack as fullstack;fullstack
pub use dioxus_liveview as liveview;liveview
pub use dioxus_ssr as ssr;ssr
pub use warnings;warnings
pub use dioxus_config_macros as config_macros;
pub use subsecond;

Modules§

asset_resolverasset
The asset resolver for the Dioxus bundle format. Each platform has its own way of resolving assets. This crate handles resolving assets in a cross-platform way.
events
prelude

Structs§

CapturedError
An anyhow::Error wrapped in an Arc so it can be cheaply cloned and passed around.
LaunchBuilderlaunch
A builder for a fullstack app.

Functions§

Ok
Equivalent to Ok::<_, dioxus::CapturedError>(value).
launchlaunch
Launch your Dioxus application with the given root component, context and config. The platform will be determined from cargo features.
serveserver
Serve a fullstack dioxus application with a custom axum router.

Type Aliases§

ContextFnlaunch
A context function is a Send and Sync closure that returns a boxed trait object
LaunchFnlaunch
Result
A result type with a default error of CapturedError.