search

Fullstack

This guide assumes you read the Web getting started guide and installed the Dioxus-cli

Setup

Before we get started, make sure you have Rust and Cargo installed. Then create a new project:

cargo new --bin demo
cd demo

Add dioxus and dioxus-fullstack as dependencies:

cargo add dioxus@0.5.0-alpha.2 --features fullstack

Next, set up features for the server (server) and the client (web). These features are what allow Dioxus to separate the client and backend from each other.

[features]
default = []
server = ["dioxus/axum"]
web = ["dioxus/web"]

Your dependencies should look roughly like this:

[dependencies]
dioxus = { version = "*", features = ["fullstack"] }

[features]
default = []
server = ["dioxus/axum"]
web = ["dioxus/web"]

Now, set up your fullstack app to serve the Dioxus app.

#![allow(non_snake_case, unused)]
use dioxus::prelude::*;

fn main() {
    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!" }
    }
}

Now, run your app with:

dx serve --platform fullstack

Finally, open http://localhost:8080 in your browser. You should see a server-side rendered page with a counter.

Hot Reload

  1. Hot reloading allows much faster iteration times inside of rsx calls by interpreting them and streaming the edits.
  2. It is useful when changing the styling/layout of a program, but will not help with changing the logic of a program.

Usage

  1. Run:
dx serve --hot-reload --platform fullstack
  1. Change some code within a rsx or render macro
  2. Save and watch the style change without recompiling

Limitations

  1. The interpreter can only use expressions that existed on the last full recompile. If you introduce a new variable or expression to the rsx call, it will require a full recompile to capture the expression.
  2. Components, Iterators, and some attributes can contain arbitrary rust code and will trigger a full recompile when changed.