docs: update local examples and docs to support new syntaxes
This commit is contained in:
1 parent
e495b09bf1
commit
4de16c4779
118 files changed
+520
-1154
No files matched your search
@@ -11,11 +11,11 @@ use dioxus_web;
|
||||
use gloo_timers::future::TimeoutFuture;
|
||||
|
||||
fn main() {
|
||||
dioxus_web::launch(App, |c| c);
|
||||
dioxus_web::launch(App);
|
||||
}
|
||||
|
||||
static App: Component<()> = |cx, props| {
|
||||
let mut count = use_state(cx, || 0);
|
||||
static App: Component<()> = |cx| {
|
||||
let mut count = use_state(&cx, || 0);
|
||||
|
||||
cx.push_task(|| async move {
|
||||
TimeoutFuture::new(100).await;
|
||||
|
||||
@@ -6,7 +6,6 @@ use dioxus_core_macro::*;
|
||||
use dioxus_hooks::{use_ref, use_state};
|
||||
use dioxus_html as dioxus_elements;
|
||||
use dioxus_web;
|
||||
use gloo_timers::future::TimeoutFuture;
|
||||
use rand::prelude::*;
|
||||
|
||||
fn main() {
|
||||
@@ -73,7 +72,7 @@ fn main() {
|
||||
wasm_bindgen::intern(&x.to_string());
|
||||
}
|
||||
|
||||
dioxus_web::launch(App, |c| c.rootname("main"));
|
||||
dioxus_web::launch(App);
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Copy)]
|
||||
@@ -107,9 +106,9 @@ impl Label {
|
||||
}
|
||||
}
|
||||
|
||||
static App: Component<()> = |cx, _props| {
|
||||
let mut items = use_ref(cx, || vec![]);
|
||||
let mut selected = use_state(cx, || None);
|
||||
static App: Component<()> = |cx| {
|
||||
let mut items = use_ref(&cx, || vec![]);
|
||||
let mut selected = use_state(&cx, || None);
|
||||
|
||||
cx.render(rsx! {
|
||||
div { class: "container"
|
||||
@@ -175,10 +174,10 @@ struct ActionButtonProps<'a> {
|
||||
onclick: &'a dyn Fn(),
|
||||
}
|
||||
|
||||
fn ActionButton(cx: Scope, props: &ActionButtonProps) -> Element {
|
||||
fn ActionButton<'a>(cx: Scope<'a, ActionButtonProps<'a>>) -> Element {
|
||||
rsx!(cx, div { class: "col-sm-6 smallpad"
|
||||
button { class:"btn btn-primary btn-block", r#type: "button", id: "{props.id}", onclick: move |_| (props.onclick)(),
|
||||
"{props.name}"
|
||||
button { class:"btn btn-primary btn-block", r#type: "button", id: "{cx.props.id}", onclick: move |_| (cx.props.onclick)(),
|
||||
"{cx.props.name}"
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -229,9 +228,9 @@ static NOUNS: &[&str] = &[
|
||||
|
||||
// fn Row(cx: Context, props: &RowProps) -> Element {
|
||||
// rsx!(cx, tr {
|
||||
// td { class:"col-md-1", "{props.row_id}" }
|
||||
// td { class:"col-md-1", "{cx.props.row_id}" }
|
||||
// td { class:"col-md-1", onclick: move |_| { /* run onselect */ }
|
||||
// a { class: "lbl", {props.label.labels} }
|
||||
// a { class: "lbl", {cx.props.label.labels} }
|
||||
// }
|
||||
// td { class: "col-md-1"
|
||||
// a { class: "remove", onclick: move |_| {/* remove */}
|
||||
|
||||
@@ -7,16 +7,14 @@ use dioxus_core as dioxus;
|
||||
use dioxus_core_macro::*;
|
||||
use dioxus_hooks::use_state;
|
||||
use dioxus_html as dioxus_elements;
|
||||
use dioxus_web;
|
||||
use gloo_timers::future::TimeoutFuture;
|
||||
|
||||
fn main() {
|
||||
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
||||
dioxus_web::launch(App, |c| c);
|
||||
dioxus_web::launch(App);
|
||||
}
|
||||
|
||||
static App: Component<()> = |cx, props| {
|
||||
let show = use_state(cx, || true);
|
||||
static App: Component<()> = |cx| {
|
||||
let show = use_state(&cx, || true);
|
||||
|
||||
let inner = match *show {
|
||||
true => {
|
||||
|
||||
@@ -11,10 +11,10 @@ use dioxus_html as dioxus_elements;
|
||||
use dioxus_web;
|
||||
|
||||
fn main() {
|
||||
dioxus_web::launch(App, |c| c);
|
||||
dioxus_web::launch(App);
|
||||
}
|
||||
|
||||
static App: Component<()> = |cx, _| {
|
||||
static App: Component<()> = |cx| {
|
||||
let doggo = cx.suspend(|| async move {
|
||||
#[derive(serde::Deserialize)]
|
||||
struct Doggo {
|
||||
|
||||
@@ -84,12 +84,12 @@ mod ric_raf;
|
||||
/// dioxus_web::launch(App);
|
||||
/// }
|
||||
///
|
||||
/// static App: Component<()> = |cx, props| {
|
||||
/// static App: Component<()> = |cx| {
|
||||
/// rsx!(cx, div {"hello world"})
|
||||
/// }
|
||||
/// ```
|
||||
pub fn launch(root_component: Component<()>) {
|
||||
launch_with_props(root_component, (), |c| c);
|
||||
launch_with_props(root_component, ());
|
||||
}
|
||||
|
||||
/// Launches the VirtualDOM from the specified component function and props.
|
||||
@@ -100,7 +100,7 @@ pub fn launch(root_component: Component<()>) {
|
||||
///
|
||||
/// ```rust
|
||||
/// fn main() {
|
||||
/// dioxus_web::launch_with_props(App, RootProps { name: String::from("joe") }, |c| c);
|
||||
/// dioxus_web::launch_with_props(App, RootProps { name: String::from("joe") });
|
||||
/// }
|
||||
///
|
||||
/// #[derive(ParitalEq, Props)]
|
||||
@@ -108,8 +108,8 @@ pub fn launch(root_component: Component<()>) {
|
||||
/// name: String
|
||||
/// }
|
||||
///
|
||||
/// static App: Component<RootProps> = |cx, props| {
|
||||
/// rsx!(cx, div {"hello {props.name}"})
|
||||
/// static App: Component<RootProps> = |cx| {
|
||||
/// rsx!(cx, div {"hello {cx.props.name}"})
|
||||
/// }
|
||||
/// ```
|
||||
pub fn launch_with_props<T, F>(
|
||||
@@ -132,7 +132,7 @@ pub fn launch_with_props<T, F>(
|
||||
///
|
||||
/// ```ignore
|
||||
/// fn main() {
|
||||
/// let app_fut = dioxus_web::run_with_props(App, RootProps { name: String::from("joe") }, |c| c);
|
||||
/// let app_fut = dioxus_web::run_with_props(App, RootProps { name: String::from("joe") });
|
||||
/// wasm_bindgen_futures::spawn_local(app_fut);
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
Reference in new issue
Block a user