Chore: some cleanup and documentation
This commit is contained in:
1 parent
fe6938ceb3
commit
517d7f1495
39 files changed
+507
-2142
No files matched your search
@@ -0,0 +1,16 @@
|
||||
# Welcome to Dioxus!
|
||||
|
||||
## Running Examples
|
||||
|
||||
We use the dedicated `dioxus-cli` to build and test dioxus web-apps. This can run examples, tests, build web workers, launch development servers, bundle, and more. It's general purpose, but currently very tailored to Dioxus for liveview and bundling. If you've not used it before, `cargo install --path pacakages/dioxus-cli` will get it installed. This CLI tool should feel like using `cargo` but with 1st party support for assets, bundling, and other important dioxus-specific features.
|
||||
|
||||
Alternatively, `trunk` works but can't run examples.
|
||||
|
||||
- tide_ssr: Handle an HTTP request and return an html body using the html! macro. `cargo run --example tide_ssr`
|
||||
- doc_generator: Use dioxus SSR to generate the website and docs. `cargo run --example doc_generator`
|
||||
- fc_macro: Use the functional component macro to build terse components. `cargo run --example fc_macro`
|
||||
- hello_web: Start a simple wasm app. Requires a web packer like dioxus-cli or trunk `cargo run --example hello`
|
||||
- router: `cargo run --example router`
|
||||
- tide_ssr: `cargo run --example tide_ssr`
|
||||
- webview: Use liveview to bridge into a webview context for a simple desktop application. `cargo run --example webview`
|
||||
- twitter-clone: A full-featured Twitter clone showcasing dioxus-liveview, state management patterns, and hooks. `cargo run --example twitter`
|
||||
@@ -0,0 +1,3 @@
|
||||
# The Server-Side-Rendering Guide
|
||||
|
||||
This guide will help you build your first app that leverages server-side-rendering to display the user interface.
|
||||
@@ -0,0 +1,3 @@
|
||||
# The WASM Guide
|
||||
|
||||
This guide will help you build your first app that leverages WASM in the browser to display the user interface.
|
||||
@@ -0,0 +1,3 @@
|
||||
# The Desktop Guide
|
||||
|
||||
This guide will help you build your first app that leverages webview for desktop to display the user interface.
|
||||
@@ -0,0 +1,19 @@
|
||||
## Concurrency
|
||||
In Dioxus, VNodes are asynchronous and can their rendering can be paused at any time by awaiting a future. Hooks can combine this functionality with the Context and Subscription APIs to craft dynamic and efficient user experiences.
|
||||
|
||||
```rust
|
||||
fn user_data(ctx: Context<()>) -> VNode {
|
||||
// Register this future as a task
|
||||
use_suspense(ctx, async {
|
||||
// Continue on with the component as usual, waiting for data to arrive
|
||||
let Profile { name, birthday, .. } = fetch_data().await;
|
||||
html! {
|
||||
<div>
|
||||
{"Hello, {name}!"}
|
||||
{if birthday === std::Instant::now() {html! {"Happy birthday!"}}}
|
||||
</div>
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
Asynchronous components are powerful but can also be easy to misuse as they pause rendering for the component and its children. Refer to the concurrent guide for information on how to best use async components.
|
||||
@@ -0,0 +1,19 @@
|
||||
## Liveview
|
||||
With the Context, Subscription, and Asynchronous APIs, we've built Dioxus Liveview: a coupling of frontend and backend to deliver user experiences that do not require dedicated API development. Instead of building and maintaining frontend-specific API endpoints, components can directly access databases, server caches, and other services directly from the component.
|
||||
|
||||
These set of features are still experimental. Currently, we're still working on making these components more ergonomic
|
||||
|
||||
```rust
|
||||
fn live_component(ctx: &Context<()>) -> VNode {
|
||||
use_live_component(
|
||||
ctx,
|
||||
// Rendered via the client
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
|| html! { <div> {"Loading data from server..."} </div> },
|
||||
|
||||
// Renderered on the server
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
|| html! { <div> {"Server Data Loaded!"} </div> },
|
||||
)
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,31 @@
|
||||
## Components
|
||||
|
||||
Dioxus should look and feel just like writing functional React components. In Dioxus, there are no class components with lifecycles. All state management is done via hooks. This encourages logic reusability and lessens the burden on Dioxus to maintain a non-breaking lifecycle API.
|
||||
|
||||
```rust
|
||||
#[derive(Properties, PartialEq)]
|
||||
struct MyProps {
|
||||
name: String
|
||||
}
|
||||
|
||||
fn Example(ctx: Context<MyProps>) -> VNode {
|
||||
html! { <div> "Hello {ctx.ctx.name}!" </div> }
|
||||
}
|
||||
```
|
||||
|
||||
Here, the `Context` object is used to access hook state, create subscriptions, and interact with the built-in context API. Props, children, and component APIs are accessible via the `Context` object. The functional component macro makes life more productive by inlining props directly as function arguments, similar to how Rocket parses URIs.
|
||||
|
||||
```rust
|
||||
// A very terse component!
|
||||
#[fc]
|
||||
fn Example(ctx: Context, name: String) -> VNode {
|
||||
html! { <div> "Hello {name}!" </div> }
|
||||
}
|
||||
|
||||
// or
|
||||
|
||||
#[functional_component]
|
||||
static Example: FC = |ctx, name: String| html! { <div> "Hello {name}!" </div> };
|
||||
```
|
||||
|
||||
The final output of components must be a tree of VNodes. We provide an html macro for using JSX-style syntax to write these, though, you could use any macro, DSL, templating engine, or the constructors directly.
|
||||
Reference in new issue
Block a user