### Install and Serve Dioxus App with CLI Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/dioxus/README.md Commands to install the Dioxus CLI and create/serve a new Dioxus application. This is the recommended way to start a new project and run it on different platforms. ```shell # 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 ``` -------------------------------- ### Serve Dioxus Application Source: https://github.com/dioxuslabs/dioxus/blob/main/examples/01-app-demos/ecommerce-site/README.md Command to start the Dioxus development server. This command automatically initializes the Tailwind CSS watcher if a tailwind.css file is detected in the project root. ```bash dx serve ``` -------------------------------- ### Running examples with Cargo Source: https://github.com/dioxuslabs/dioxus/blob/main/README.md Command to run examples from the main branch of the Dioxus repository using Cargo. ```sh cargo run --example ``` -------------------------------- ### Serving examples with Dioxus CLI for Web Source: https://github.com/dioxuslabs/dioxus/blob/main/README.md Command to serve examples using the Dioxus CLI for the web platform, disabling default features. ```sh dx serve --example --platform web -- --no-default-features ``` -------------------------------- ### Run Dioxus Application Source: https://github.com/dioxuslabs/dioxus/blob/main/examples/01-app-demos/file-explorer/README.md Execute this command in the terminal to start the development server for the Dioxus application. ```bash dx serve ``` -------------------------------- ### Install and Verify CLI Source: https://github.com/dioxuslabs/dioxus/blob/main/notes/RELEASING.md Commands to install the local version of the Dioxus CLI and update dependencies to ensure the release environment is consistent with the current repository state. ```shell cargo install --path packages/cli cargo update ``` -------------------------------- ### Installing Dioxus CLI from Git Source: https://github.com/dioxuslabs/dioxus/blob/main/README.md Command to install the Dioxus CLI directly from its Git repository using Cargo. ```sh cargo install --git https://github.com/DioxusLabs/dioxus dioxus-cli --locked ``` -------------------------------- ### Installing Dioxus CLI Source: https://github.com/dioxuslabs/dioxus/blob/main/README.md Command to install the Dioxus CLI using a shell script. ```sh curl -fsSL https://dioxuslabs.com/install.sh | bash ``` -------------------------------- ### Complete Dioxus App Example with Permissions Source: https://github.com/dioxuslabs/dioxus/blob/main/notes/architecture/12-MANIFEST-SYSTEM.md A comprehensive Dioxus.toml example for a geolocation app, demonstrating unified permissions for location and notifications, along with platform-specific settings for iOS and macOS. This showcases how to configure an application's core features and platform integrations. ```toml [application] name = "GeoTracker" [bundle] identifier = "com.example.geotracker" # Unified permissions - automatically mapped to each platform [permissions] location = { precision = "fine", description = "Track your precise location for navigation" } notifications = { description = "Send alerts when you arrive at destinations" } # iOS-specific settings [ios] deployment_target = "15.0" [ios.plist] UIBackgroundModes = ["location"] [ios.entitlements] "com.apple.developer.healthkit" = false # Android-specific settings [android] min_sdk = 24 target_sdk = 34 features = ["android.hardware.location.gps"] # macOS-specific settings [macos] minimum_system_version = "11.0" [macos.entitlements] "com.apple.security.app-sandbox" = true ``` -------------------------------- ### Basic Dioxus App Structure Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/dioxus/README.md A minimal Dioxus application demonstrating a counter with buttons to increment and decrement. This example shows the basic structure of a Dioxus app, including launching the app and defining the UI with signals for state management. ```rust 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!" } } } ``` -------------------------------- ### Initializing and Rebuilding Virtual DOM (Rust) Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/core/README.md Illustrates how to initialize a Dioxus Virtual DOM with a root component and generate the initial set of mutations for rendering. This is a fundamental step for starting a Dioxus application. ```rust # use dioxus::dioxus_core::{Mutations, VirtualDom}; use dioxus::prelude::*; // First, declare a root component fn app() -> Element { rsx! { div { "hello world" } } } fn main() { // Next, create a new VirtualDom using this app as the root component. let mut dom = VirtualDom::new(app); // The initial render of the dom will generate a stream of edits for the real dom to apply let mutations = dom.rebuild_to_vec(); } ``` -------------------------------- ### Initialize and Use Dioxus Logger Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/logger/README.md Demonstrates how to initialize the logger with a specific tracing level and use the info macro within a Dioxus component. This setup ensures logs are captured across different platform targets. ```rust use dioxus::prelude::*; use dioxus_logger::tracing::{Level, info}; fn main() { dioxus_logger::init(Level::INFO).expect("logger failed to init"); dioxus::launch(App); } #[component] fn App() -> Element { info!("App rendered"); rsx! { p { "hi" } } } ``` ```rust use dioxus::prelude::*; use dioxus::logger::tracing::{Level, info}; fn main() { dioxus::logger::init(Level::INFO).expect("logger failed to init"); dioxus::launch(App); } #[component] fn App() -> Element { info!("App rendered"); rsx! { p { "hi" } } } ``` -------------------------------- ### Diffing Algorithm Entry Point Source: https://github.com/dioxuslabs/dioxus/blob/main/notes/architecture/01-CORE.md Identifies the starting point for the diffing algorithm, `diff_scope()`, which compares old and new VNodes to determine necessary DOM mutations. ```rust // Entry point for diffing diff_scope(old_vnode, new_vnode, dom, mutations) ``` -------------------------------- ### Install Dioxus CLI Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/cli/README.md Commands to install the Dioxus CLI tool using Cargo. Users can choose between the stable version, the latest development build from git, or a local build. ```shell cargo install dioxus-cli ``` ```shell cargo install --git https://github.com/DioxusLabs/dioxus dioxus-cli ``` ```shell cargo install --path . ``` -------------------------------- ### Rust: Store Path Tracking Example Source: https://github.com/dioxuslabs/dioxus/blob/main/notes/architecture/04-SIGNALS.md Demonstrates how Dioxus Stores track changes to nested fields. Writing to a nested field only invalidates subscribers whose paths include that specific field, ensuring granular reactivity. ```rust let store = Store::new(vec![a, b, c]); let item_1 = store[1]; // path = [1] let field = item_1.name; // path = [1, field_hash] // Writing store[1].name only marks dirty: // - subscribers at path [1] // - subscribers at path [1, field_hash] // - NOT path [0] or [2] ``` -------------------------------- ### Filename Generation Examples Source: https://github.com/dioxuslabs/dioxus/blob/main/notes/architecture/08-ASSETS.md Illustrates how different asset types are transformed with hash-based cache busting in their filenames. ```rust IMAGE: /assets/photo.png → /assets/photo-{hash}.webp CSS/JS: /assets/style.css → /assets/style-{hash}.css FOLDER: /assets (folder) → /assets/ (unchanged) ``` -------------------------------- ### Demonstrate use_resource Reactivity with Server Requests (Rust) Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/hooks/docs/use_resource.md Illustrates the reactive nature of `use_resource` by creating a resource that doubles a signal's value via a simulated server request. It shows how changes to the `count` signal trigger the resource to rerun, updating the result. The example also details how to check the resource's state (`Pending`, `Done`, `Stopped`) and retrieve its value at different stages. ```rust # use dioxus::prelude::* // Create a new count signal let mut count = use_signal(|| 1); // Create a new resource that doubles the value of count let double_count = use_resource(move || async move { // Start a request to the server. We are reading the value of count in the format macro // Reading the value of count makes the resource "subscribe" to changes to count (when count changes, the resource will rerun) let response = reqwest::get(format!("https://myserver.com/doubleme?count={count}")).await.unwrap(); response.text().await.unwrap() }); // Resource can be read in a way that is similar to signals, but they have a bit of extra information about the state of the resource future. // Calling .state() on a resource will return a Signal with information about the current status of the resource println!("{:?}", double_count.state().read()); // Prints "UseResourceState::Pending" // You can also try to get the last resolved value of the resource with the .value() method println!("{:?}", double_count.read()); // Prints "None" // Wait for the resource to finish and get the value std::thread::sleep(std::time::Duration::from_secs(1)); // Now if we read the state, we will see that it is done println!("{:?}", double_count.state().read()); // Prints "UseResourceState::Done" // And we can get the value println!("{:?}", double_count.read()); // Prints "Some(2)" // Now if we write to count, the resource will rerun count += 1; // count is now 2 // Wait for the resource to finish and get the value std::thread::sleep(std::time::Duration::from_secs(1)); // Now if we read the state, we will see that it is done println!("{:?}", double_count.state().read()); // Prints "UseResourceState::Done" // And we can get the value println!("{:?}", double_count.read()); // Prints "Some(4)" // One more case, what happens if we write to the resource while it is in progress? // The resource will rerun and the value will be None count += 1; // count is now 3 // If we write to a value the resource subscribes to again, it will cancel the current future and start a new one count += 1; // count is now 4 println!("{:?}", double_count.state().read()); // Prints "UseResourceState::Stopped" println!("{:?}", double_count.read()); // Prints the last resolved value "Some(4)" // After we wait for the resource to finish, we will get the value of only the latest future std::thread::sleep(std::time::Duration::from_secs(1)); println!("{:?}", double_count.state().read()); // Prints "UseResourceState::Done" println!("{:?}", double_count.read()); // Prints "Some(8)" ``` -------------------------------- ### CSS Module Integration Example Source: https://github.com/dioxuslabs/dioxus/blob/main/notes/architecture/08-ASSETS.md Demonstrates how to use the `css_module!()` macro to generate Rust structs with scoped CSS class names, which are automatically injected on dereference. ```rust css_module!(Styles = "/my.module.css", AssetOptions::css_module()); // Generates: struct Styles {} impl Styles { pub const header: &str = "abc[hash]"; // Unique scoped class pub const button: &str = "def[hash]"; } ``` -------------------------------- ### Implementing Local Subscriptions Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/signals/README.md Shows how signals trigger re-renders only in components that read the signal value. This example demonstrates passing signals through props and the context API to optimize component updates. ```rust use dioxus::prelude::*; use dioxus_signals::*; #[component] fn App() -> Element { let mut signal = use_signal(|| 0); rsx! { button { onclick: move |_| { signal += 1; }, "Increase" } for id in 0..10 { Child { signal } } } } #[derive(Props, Clone, PartialEq)] struct ChildProps { signal: Signal, } fn Child(props: ChildProps) -> Element { rsx! { "{props.signal}" } } #[component] fn ContextApp() -> Element { use_context_provider(|| Signal::new(0)); rsx! { ChildComponent {} } } #[component] fn ChildComponent() -> Element { let signal: Signal = use_context(); rsx! { "{signal}" } } ``` -------------------------------- ### Manage Memo Lifecycle and Dependencies Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/hooks/docs/derived_state.md Shows how memos act as read-only signals and how they trigger downstream updates only when their output value changes. This example illustrates the reactive chain between multiple memos. ```rust let mut count = use_signal(|| 1); let double_count = use_memo(move || count() * 2); println!("{}", double_count); count += 1; println!("{}", double_count); let double_count_plus_one = use_memo(move || double_count() + 1); println!("{}", double_count_plus_one); count += 1; println!("{}", double_count); println!("{}", double_count_plus_one); *count.write() = 3; println!("{}", double_count); println!("{}", double_count_plus_one); ``` -------------------------------- ### Implement Reactive Nested Data with Dioxus Stores Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/stores/README.md Demonstrates how to derive the Store trait on a data structure and use it within Dioxus components. The example shows how to scope stores to specific fields like 'count' and 'children' to achieve granular reactivity. ```rust use dioxus::prelude::*; use dioxus_stores::*; fn main() { dioxus::launch(app); } #[derive(Store, Default)] struct CounterTree { count: i32, children: Vec, } fn app() -> Element { let value = use_store(Default::default); rsx! { Tree { value } } } #[component] fn Tree(value: Store) -> Element { let mut count = value.count(); let mut children = value.children(); rsx! { button { onclick: move |_| count += 1, "Increment" } button { onclick: move |_| children.push(Default::default()), "Push child" } ul { for value in children.iter() { li { Tree { value } } } } } } ``` -------------------------------- ### Install Linux Dependencies for Dioxus Source: https://github.com/dioxuslabs/dioxus/blob/main/notes/CONTRIBUTING.md Installs the required GTK and WebKit development libraries on Linux systems. These dependencies are necessary for building and running Dioxus applications that utilize webview components. ```bash sudo apt install libgdk3.0-cil libatk1.0-dev libcairo2-dev libpango1.0-dev libgdk-pixbuf2.0-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev libwebkit2gtk-4.1-dev ``` -------------------------------- ### Basic Dioxus Desktop App Structure Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/desktop/src/readme.md This is the main entry point for a Dioxus Desktop application. It launches the app using the provided component. ```rust use dioxus::prelude::*; fn main() { dioxus_desktop::launch(app); } fn app() -> Element { rsx! { div { "hello world!" } } } ``` -------------------------------- ### Create a new Dioxus project Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/desktop/src/readme.md Use cargo to create a new binary project and navigate into the directory. ```shell cargo new --bin demo cd app ``` -------------------------------- ### Package and Publish Dioxus Extension Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/extension/DEV.md Navigate to your extension's directory and use `vsce package` to create a `.vsix` file. Then, use `vsce publish` to upload it to the VS Code Marketplace. ```bash cd myExtension vsce package # myExtension.vsix generated vsce publish # .myExtension published to VS Code Marketplace ``` -------------------------------- ### Initialize Dioxus Project Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/cli/README.md Command to initialize a new Dioxus project using the CLI. It clones the project from the official template repository. ```shell dx new --template gh:dioxuslabs/dioxus-template ``` -------------------------------- ### Rust Compilation Error Example Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/cli/assets/web/dev.loading.html An example of a diagnostic error message generated by the Rust compiler when using the Dioxus rsx! macro. This demonstrates a common syntax error where a semicolon is missing before the macro invocation. ```rust error: expected `;`, found `rsx` --> src/main.rs:21:6 | 21 | a | ^ help: add `;` here 22 | rsx! { | --- unexpected token error: could not compile `my-cool-app` (bin "my-cool-app") due to 1 previous error ``` -------------------------------- ### Rust Hot-patching with Subsecond Source: https://github.com/dioxuslabs/dioxus/blob/main/notes/releases/0.7.0-alpha.0.md Demonstrates how to use the Subsecond library for hot-patching Rust code at runtime. This allows for simultaneous iteration on frontend and backend code without restarting the application. It requires explicit integration points using `subsecond::call`. ```rust pub fn launch() { loop { std::thread::sleep(std::time::Duration::from_secs(1)); subsecond::call(|| tick()); } } fn tick() { println!("edit me to see the loop in action!!!!!!!!! "); } ``` -------------------------------- ### Add Dioxus and Desktop Renderer Dependencies Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/desktop/src/readme.md Add the necessary Dioxus and dioxus-desktop crates to your project's Cargo.toml file. ```shell cargo add dioxus cargo add dioxus-desktop ``` -------------------------------- ### Future Concepts - secret!() Macro Source: https://github.com/dioxuslabs/dioxus/blob/main/notes/architecture/08-ASSETS.md Example of a secret!() macro for compile-time validation and runtime injection of secrets from secure stores. ```rust const API_KEY: Secret = secret!("DIOXUS_API_KEY"); // Compile-time validation // Runtime injection from secure store ``` -------------------------------- ### Define Application Routes with Routable Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/hooks/README.md The Router component uses a derived Routable enum to manage navigation. This example demonstrates defining a route with a dynamic parameter. ```rust #[derive(Routable, Clone, PartialEq)] enum Route { #[route("/user/:id")] Homepage { id: u32 } } ``` -------------------------------- ### Run Dioxus Workspace Tests Source: https://github.com/dioxuslabs/dioxus/blob/main/notes/CONTRIBUTING.md Executes the full test suite for the Dioxus workspace using Cargo. This command verifies the integrity of all crates within the project. ```bash cargo test --workspace --tests ``` -------------------------------- ### Configure JavaScript Assets with AssetOptions Source: https://github.com/dioxuslabs/dioxus/blob/main/packages/manganis/manganis/README.md Configure JavaScript assets for minification, static head inclusion, preloading, and module type. Options include `with_minify`, `with_static_head`, `with_preload`, and `with_module`. ```rust use manganis::{asset, Asset, AssetOptions}; // Vendored UMD library: copy verbatim, emitted as a classic