cd ../blog

What is Dioxus, How to Build?

> 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.

What is Dioxus, How to Build?

Dioxus: A Fullstack Cross-Platform App Framework for Rust

Dioxus is a fullstack and cross-platform framework for building web, desktop, mobile, and server apps using Rust. It offers a React-like development experience with features like components, props, and hooks, but with Rust's performance and safety. Key features include ergonomic state management, type-safe routing, an integrated bundler, and instant hot-reloading. Dioxus supports various platforms, including web (with SSR and hydration), desktop (macOS, Linux, Windows), and mobile (Android, iOS).

Building with Dioxus: A Step-by-Step Guide

The process of building with Dioxus involves several key steps:

1. Prerequisites:

  • An Editor: Dioxus works well with editors supporting the Rust-Analyzer LSP plugin for enhanced code assistance.
  • Rust: Install the Rust compiler from . It's highly recommended to work through the official Rust book () for a solid foundation.

2. Installation:

Install the Dioxus CLI (dx) using:

If you encounter OpenSSL errors, ensure the necessary dependencies are installed (refer to for details).

3. Creating a New Project:

Use the CLI to create a new project:

You'll be prompted to select a platform (Web, Desktop, Mobile, etc.), a styling library (e.g., vanilla CSS), and whether to enable routing.

4. Running Your App:

Start the development server:

For LiveView templates, use dx serve --desktop. For web targets, the application will be served at a specified address.

5. Core Concepts:

  • Components: Reusable UI elements built using functions returning Element. The #[component] attribute simplifies component creation and prop management.
  • rsx! Macro: A JSX-like macro for creating elements with attributes, listeners, and children. Attributes and listeners are listed before children.
  • Hooks: Reusable logic units for managing state and side effects within components. They start with use_ (e.g., use_signal). Adhere to the "rules of hooks" for correct usage.

6. Example: A Simple Counter

A basic Dioxus counter app demonstrates core concepts:

7. Further Learning:

Explore the Dioxus documentation () for tutorials, guides, and advanced topics like server-side rendering, concurrent rendering, and platform-specific details. The Dioxus website also serves as a testbed for new features.

Dioxus Multiplatform Icon
Dioxus Hot Reloading
Dioxus Android and iOS Support
Dioxus Bundling
Dioxus Documentation
Dioxus Community

*_