diff --git a/README.md b/README.md index 7e31285a..4ef6acfe 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Dioxus is a portable, performant, and ergonomic framework for building cross-pla ```rust fn app(cx: Scope) -> Element { - let mut count = use_state(&cx, || 0); + let mut count = use_state(cx, || 0); cx.render(rsx! { h1 { "High-Five counter: {count}" } diff --git a/docs/guide/examples/conditional_rendering.rs b/docs/guide/examples/conditional_rendering.rs index 5a89ef4e..490cbfee 100644 --- a/docs/guide/examples/conditional_rendering.rs +++ b/docs/guide/examples/conditional_rendering.rs @@ -6,7 +6,7 @@ fn main() { } pub fn App(cx: Scope) -> Element { - let is_logged_in = use_state(&cx, || false); + let is_logged_in = use_state(cx, || false); cx.render(rsx!(LogIn { is_logged_in: **is_logged_in, diff --git a/docs/guide/examples/hooks_bad.rs b/docs/guide/examples/hooks_bad.rs index 4fb389bb..97b60d2f 100644 --- a/docs/guide/examples/hooks_bad.rs +++ b/docs/guide/examples/hooks_bad.rs @@ -17,13 +17,13 @@ fn App(cx: Scope) -> Element { // But `if` statements only run if the conditional is true! // So we might violate rule 2. if you_are_happy && you_know_it { - let something = use_state(&cx, || "hands"); + let something = use_state(cx, || "hands"); println!("clap your {something}") } // ✅ instead, *always* call use_state // You can put other stuff in the conditional though - let something = use_state(&cx, || "hands"); + let something = use_state(cx, || "hands"); if you_are_happy && you_know_it { println!("clap your {something}") } @@ -33,12 +33,12 @@ fn App(cx: Scope) -> Element { // ❌ don't call hooks inside closures! // We can't guarantee that the closure, if used, will be called at the same time every time let _a = || { - let b = use_state(&cx, || 0); + let b = use_state(cx, || 0); b.get() }; // ✅ instead, move hook `b` outside - let b = use_state(&cx, || 0); + let b = use_state(cx, || 0); let _a = || b.get(); // ANCHOR_END: closure @@ -50,12 +50,12 @@ fn App(cx: Scope) -> Element { // ❌ Do not use hooks in loops! // In this case, if the length of the Vec changes, we break rule 2 for _name in &names { - let is_selected = use_state(&cx, || false); + let is_selected = use_state(cx, || false); println!("selected: {is_selected}"); } // ✅ Instead, use a hashmap with use_ref - let selection_map = use_ref(&cx, HashMap::<&str, bool>::new); + let selection_map = use_ref(cx, HashMap::<&str, bool>::new); for name in &names { let is_selected = selection_map.read()[name]; diff --git a/docs/guide/examples/hooks_counter.rs b/docs/guide/examples/hooks_counter.rs index f717ba65..1fb2a0bd 100644 --- a/docs/guide/examples/hooks_counter.rs +++ b/docs/guide/examples/hooks_counter.rs @@ -7,7 +7,7 @@ fn main() { // ANCHOR: component fn App(cx: Scope) -> Element { - let mut count = use_state(&cx, || 0); + let mut count = use_state(cx, || 0); cx.render(rsx!( h1 { "High-Five counter: {count}" } diff --git a/docs/guide/examples/hooks_counter_two_state.rs b/docs/guide/examples/hooks_counter_two_state.rs index 75fcb911..b2a8f6e7 100644 --- a/docs/guide/examples/hooks_counter_two_state.rs +++ b/docs/guide/examples/hooks_counter_two_state.rs @@ -8,8 +8,8 @@ fn main() { // ANCHOR: component fn App(cx: Scope) -> Element { // ANCHOR: use_state_calls - let mut count_a = use_state(&cx, || 0); - let mut count_b = use_state(&cx, || 0); + let mut count_a = use_state(cx, || 0); + let mut count_b = use_state(cx, || 0); // ANCHOR_END: use_state_calls cx.render(rsx!( diff --git a/docs/guide/examples/hooks_use_ref.rs b/docs/guide/examples/hooks_use_ref.rs index 862937aa..4910325d 100644 --- a/docs/guide/examples/hooks_use_ref.rs +++ b/docs/guide/examples/hooks_use_ref.rs @@ -7,7 +7,7 @@ fn main() { // ANCHOR: component fn App(cx: Scope) -> Element { - let list = use_ref(&cx, Vec::new); + let list = use_ref(cx, Vec::new); let list_formatted = format!("{:?}", *list.read()); cx.render(rsx!( diff --git a/docs/guide/examples/input_controlled.rs b/docs/guide/examples/input_controlled.rs index b58fe58a..bf92072a 100644 --- a/docs/guide/examples/input_controlled.rs +++ b/docs/guide/examples/input_controlled.rs @@ -7,7 +7,7 @@ fn main() { // ANCHOR: component fn App(cx: Scope) -> Element { - let name = use_state(&cx, || "bob".to_string()); + let name = use_state(cx, || "bob".to_string()); cx.render(rsx! { input { diff --git a/docs/guide/examples/meme_editor.rs b/docs/guide/examples/meme_editor.rs index ecf75ccb..6ea0a2f4 100644 --- a/docs/guide/examples/meme_editor.rs +++ b/docs/guide/examples/meme_editor.rs @@ -18,7 +18,7 @@ fn MemeEditor(cx: Scope) -> Element { width: fit-content; "; - let caption = use_state(&cx, || "me waiting for my rust code to compile".to_string()); + let caption = use_state(cx, || "me waiting for my rust code to compile".to_string()); cx.render(rsx! { div { diff --git a/docs/guide/examples/meme_editor_dark_mode.rs b/docs/guide/examples/meme_editor_dark_mode.rs index 41283df7..96fc7681 100644 --- a/docs/guide/examples/meme_editor_dark_mode.rs +++ b/docs/guide/examples/meme_editor_dark_mode.rs @@ -14,10 +14,10 @@ struct DarkMode(bool); pub fn App(cx: Scope) -> Element { // ANCHOR: context_provider - use_context_provider(&cx, || DarkMode(false)); + use_context_provider(cx, || DarkMode(false)); // ANCHOR_END: context_provider - let is_dark_mode = use_is_dark_mode(&cx); + let is_dark_mode = use_is_dark_mode(cx); let wrapper_style = if is_dark_mode { r" @@ -47,7 +47,7 @@ pub fn use_is_dark_mode(cx: &ScopeState) -> bool { // ANCHOR: toggle pub fn DarkModeToggle(cx: Scope) -> Element { - let dark_mode = use_context::(&cx)?; + let dark_mode = use_context::(cx)?; let style = if dark_mode.read().0 { "color:white" @@ -71,7 +71,7 @@ pub fn DarkModeToggle(cx: Scope) -> Element { // ANCHOR: meme_editor fn MemeEditor(cx: Scope) -> Element { - let is_dark_mode = use_is_dark_mode(&cx); + let is_dark_mode = use_is_dark_mode(cx); let heading_style = if is_dark_mode { "color: white" } else { "" }; let container_style = r" @@ -82,7 +82,7 @@ fn MemeEditor(cx: Scope) -> Element { width: fit-content; "; - let caption = use_state(&cx, || "me waiting for my rust code to compile".to_string()); + let caption = use_state(cx, || "me waiting for my rust code to compile".to_string()); cx.render(rsx! { div { @@ -152,7 +152,7 @@ fn CaptionEditor<'a>( caption: &'a str, on_input: EventHandler<'a, FormData>, ) -> Element<'a> { - let is_dark_mode = use_is_dark_mode(&cx); + let is_dark_mode = use_is_dark_mode(cx); let colors = if is_dark_mode { r" diff --git a/docs/guide/examples/rendering_lists.rs b/docs/guide/examples/rendering_lists.rs index deb32f1f..75dc69b5 100644 --- a/docs/guide/examples/rendering_lists.rs +++ b/docs/guide/examples/rendering_lists.rs @@ -14,9 +14,9 @@ struct Comment { pub fn App(cx: Scope) -> Element { // ANCHOR: render_list - let comment_field = use_state(&cx, String::new); - let mut next_id = use_state(&cx, || 0); - let comments = use_ref(&cx, Vec::::new); + let comment_field = use_state(cx, String::new); + let mut next_id = use_state(cx, || 0); + let comments = use_ref(cx, Vec::::new); let comments_lock = comments.read(); let comments_rendered = comments_lock.iter().map(|comment| { diff --git a/docs/guide/examples/spawn.rs b/docs/guide/examples/spawn.rs index 9ba8e18f..71373e72 100644 --- a/docs/guide/examples/spawn.rs +++ b/docs/guide/examples/spawn.rs @@ -8,7 +8,7 @@ fn main() { fn App(cx: Scope) -> Element { // ANCHOR: spawn - let logged_in = use_state(&cx, || false); + let logged_in = use_state(cx, || false); let log_in = move |_| { cx.spawn({ @@ -62,10 +62,10 @@ pub fn Tokio(cx: Scope) -> Element { } pub fn ToOwnedMacro(cx: Scope) -> Element { - let count = use_state(&cx, || 0); - let age = use_state(&cx, || 0); - let name = use_state(&cx, || 0); - let description = use_state(&cx, || 0); + let count = use_state(cx, || 0); + let age = use_state(cx, || 0); + let name = use_state(cx, || 0); + let description = use_state(cx, || 0); let _ = || { // ANCHOR: to_owned_macro diff --git a/docs/guide/examples/use_future.rs b/docs/guide/examples/use_future.rs index 445c8675..b9e2f07a 100644 --- a/docs/guide/examples/use_future.rs +++ b/docs/guide/examples/use_future.rs @@ -14,7 +14,7 @@ struct ApiResponse { fn App(cx: Scope) -> Element { // ANCHOR: use_future - let future = use_future(&cx, (), |_| async move { + let future = use_future(cx, (), |_| async move { reqwest::get("https://dog.ceo/api/breeds/image/random") .await .unwrap() @@ -47,7 +47,7 @@ fn App(cx: Scope) -> Element { #[inline_props] fn RandomDog(cx: Scope, breed: String) -> Element { // ANCHOR: dependency - let future = use_future(&cx, (breed,), |(breed,)| async move { + let future = use_future(cx, (breed,), |(breed,)| async move { reqwest::get(format!("https://dog.ceo/api/breed/{breed}/images/random")) .await .unwrap() diff --git a/docs/guide/src/en/__unused/advanced-guides/12-signals.md b/docs/guide/src/en/__unused/advanced-guides/12-signals.md index 6b0f3ffe..c7012a11 100644 --- a/docs/guide/src/en/__unused/advanced-guides/12-signals.md +++ b/docs/guide/src/en/__unused/advanced-guides/12-signals.md @@ -12,7 +12,7 @@ Your component today might look something like this: ```rust fn Comp(cx: Scope) -> DomTree { - let (title, set_title) = use_state(&cx, || "Title".to_string()); + let (title, set_title) = use_state(cx, || "Title".to_string()); cx.render(rsx!{ input { value: title, @@ -26,7 +26,7 @@ This component is fairly straightforward – the input updates its own value on ```rust fn Comp(cx: Scope) -> DomTree { - let (title, set_title) = use_state(&cx, || "Title".to_string()); + let (title, set_title) = use_state(cx, || "Title".to_string()); cx.render(rsx!{ div { input { @@ -49,7 +49,7 @@ We can use signals to generate a two-way binding between data and the input box. ```rust fn Comp(cx: Scope) -> DomTree { - let mut title = use_signal(&cx, || String::from("Title")); + let mut title = use_signal(cx, || String::from("Title")); cx.render(rsx!(input { value: title })) } ``` @@ -58,8 +58,8 @@ For a slightly more interesting example, this component calculates the sum betwe ```rust fn Calculator(cx: Scope) -> DomTree { - let mut a = use_signal(&cx, || 0); - let mut b = use_signal(&cx, || 0); + let mut a = use_signal(cx, || 0); + let mut b = use_signal(cx, || 0); let mut c = a + b; rsx! { input { value: a } @@ -72,8 +72,8 @@ fn Calculator(cx: Scope) -> DomTree { Do you notice how we can use built-in operations on signals? Under the hood, we actually create a new derived signal that depends on `a` and `b`. Whenever `a` or `b` update, then `c` will update. If we need to create a new derived signal that's more complex than a basic operation (`std::ops`) we can either chain signals together or combine them: ```rust -let mut a = use_signal(&cx, || 0); -let mut b = use_signal(&cx, || 0); +let mut a = use_signal(cx, || 0); +let mut b = use_signal(cx, || 0); // Chain signals together using the `with` method let c = a.with(b).map(|(a, b)| *a + *b); @@ -84,7 +84,7 @@ let c = a.with(b).map(|(a, b)| *a + *b); If we ever need to get the value out of a signal, we can simply `deref` it. ```rust -let mut a = use_signal(&cx, || 0); +let mut a = use_signal(cx, || 0); let c = *a + *b; ``` @@ -97,7 +97,7 @@ Sometimes you want a signal to propagate across your app, either through far-awa ```rust const TITLE: Atom = || "".to_string(); const Provider: Component = |cx|{ - let title = use_signal(&cx, &TITLE); + let title = use_signal(cx, &TITLE); render!(input { value: title }) }; ``` @@ -106,7 +106,7 @@ If we use the `TITLE` atom in another component, we can cause updates to flow be ```rust const Receiver: Component = |cx|{ - let title = use_signal(&cx, &TITLE); + let title = use_signal(cx, &TITLE); log::info!("This will only be called once!"); rsx!(cx, div { @@ -133,7 +133,7 @@ Dioxus automatically understands how to use your signals when mixed with iterato ```rust const DICT: AtomFamily = |_| {}; const List: Component = |cx|{ - let dict = use_signal(&cx, &DICT); + let dict = use_signal(cx, &DICT); cx.render(rsx!( ul { For { each: dict, map: |k, v| rsx!( li { "{v}" }) } diff --git a/docs/guide/src/en/__unused/composing.md b/docs/guide/src/en/__unused/composing.md index 5746d647..06648a4c 100644 --- a/docs/guide/src/en/__unused/composing.md +++ b/docs/guide/src/en/__unused/composing.md @@ -59,7 +59,7 @@ If we represented the reactive graph presented above in Dioxus, it would look ve // Declare a component that holds our datasources and calculates `g` fn RenderGraph(cx: Scope) -> Element { let seconds = use_datasource(SECONDS); - let constant = use_state(&cx, || 1); + let constant = use_state(cx, || 1); cx.render(rsx!( RenderG { seconds: seconds } diff --git a/docs/guide/src/en/__unused/fanout.md b/docs/guide/src/en/__unused/fanout.md index 087d4b54..20c4c997 100644 --- a/docs/guide/src/en/__unused/fanout.md +++ b/docs/guide/src/en/__unused/fanout.md @@ -28,8 +28,8 @@ If we used global state like use_context or fermi, we might be tempted to inject ```rust fn Titlebar(cx: Scope) -> Element { - let title = use_read(&cx, TITLE); - let subtitle = use_read(&cx, SUBTITLE); + let title = use_read(cx, TITLE); + let subtitle = use_read(cx, SUBTITLE); cx.render(rsx!{/* ui */}) } @@ -43,11 +43,11 @@ To enable our titlebar component to be used across apps, we want to lift our ato ```rust fn DocsiteTitlesection(cx: Scope) { - let title = use_read(&cx, TITLE); - let subtitle = use_read(&cx, SUBTITLE); + let title = use_read(cx, TITLE); + let subtitle = use_read(cx, SUBTITLE); - let username = use_read(&cx, USERNAME); - let points = use_read(&cx, POINTS); + let username = use_read(cx, USERNAME); + let points = use_read(cx, POINTS); cx.render(rsx!{ TitleBar { title: title, subtitle: subtitle } diff --git a/docs/guide/src/en/__unused/localstate.md b/docs/guide/src/en/__unused/localstate.md index bf5ae701..2a20d77d 100644 --- a/docs/guide/src/en/__unused/localstate.md +++ b/docs/guide/src/en/__unused/localstate.md @@ -13,7 +13,7 @@ struct Todo { is_editing: bool, } -let todos = use_ref(&cx, || vec![Todo::new()]); +let todos = use_ref(cx, || vec![Todo::new()]); cx.render(rsx!{ ul { @@ -40,7 +40,7 @@ Instead, let's refactor our Todo component to handle its own state: ```rust #[inline_props] fn Todo<'a>(cx: Scope, todo: &'a Todo) -> Element { - let is_hovered = use_state(&cx, || false); + let is_hovered = use_state(cx, || false); cx.render(rsx!{ li { @@ -80,15 +80,15 @@ struct State { } // in the component -let state = use_ref(&cx, State::new) +let state = use_ref(cx, State::new) ``` The "better" approach for this particular component would be to break the state apart into different values: ```rust -let count = use_state(&cx, || 0); -let color = use_state(&cx, || "red"); -let names = use_state(&cx, HashMap::new); +let count = use_state(cx, || 0); +let color = use_state(cx, || "red"); +let names = use_state(cx, HashMap::new); ``` You might recognize that our "names" value is a HashMap – which is not terribly cheap to clone every time we update its value. To solve this issue, we *highly* suggest using a library like [`im`](https://crates.io/crates/im) which will take advantage of structural sharing to make clones and mutations much cheaper. @@ -96,7 +96,7 @@ You might recognize that our "names" value is a HashMap – which is not terribl When combined with the `make_mut` method on `use_state`, you can get really succinct updates to collections: ```rust -let todos = use_state(&cx, im_rc::HashMap::default); +let todos = use_state(cx, im_rc::HashMap::default); todos.make_mut().insert("new todo", Todo { contents: "go get groceries", diff --git a/docs/guide/src/en/__unused/memoization.md b/docs/guide/src/en/__unused/memoization.md index ef476a45..9bd0e8b2 100644 --- a/docs/guide/src/en/__unused/memoization.md +++ b/docs/guide/src/en/__unused/memoization.md @@ -8,8 +8,8 @@ For example, let's say we have a component that has two children: ```rust fn Demo(cx: Scope) -> Element { // don't worry about these 2, we'll cover them later - let name = use_state(&cx, || String::from("bob")); - let age = use_state(&cx, || 21); + let name = use_state(cx, || String::from("bob")); + let age = use_state(cx, || 21); cx.render(rsx!{ Name { name: name } diff --git a/docs/guide/src/en/__unused/model_pattern.md b/docs/guide/src/en/__unused/model_pattern.md index 67f21321..e66b6981 100644 --- a/docs/guide/src/en/__unused/model_pattern.md +++ b/docs/guide/src/en/__unused/model_pattern.md @@ -20,7 +20,7 @@ Our component is really simple – we just call `use_ref` to get an initial calc ```rust fn app(cx: Scope) -> Element { - let state = use_ref(&cx, Calculator::new); + let state = use_ref(cx, Calculator::new); cx.render(rsx!{ // the rendering code diff --git a/docs/guide/src/en/async/use_coroutine.md b/docs/guide/src/en/async/use_coroutine.md index b3228b3e..326141b2 100644 --- a/docs/guide/src/en/async/use_coroutine.md +++ b/docs/guide/src/en/async/use_coroutine.md @@ -10,7 +10,7 @@ The basic setup for coroutines is the `use_coroutine` hook. Most coroutines we w ```rust fn app(cx: Scope) -> Element { - let ws: &UseCoroutine<()> = use_coroutine(&cx, |rx| async move { + let ws: &UseCoroutine<()> = use_coroutine(cx, |rx| async move { // Connect to some sort of service let mut conn = connect_to_ws_server().await; @@ -27,7 +27,7 @@ For many services, a simple async loop will handle the majority of use cases. However, if we want to temporarily disable the coroutine, we can "pause" it using the `pause` method, and "resume" it using the `resume` method: ```rust -let sync: &UseCoroutine<()> = use_coroutine(&cx, |rx| async move { +let sync: &UseCoroutine<()> = use_coroutine(cx, |rx| async move { // code for syncing }); @@ -63,7 +63,7 @@ enum ProfileUpdate { SetAge(i32) } -let profile = use_coroutine(&cx, |mut rx: UnboundedReciver| async move { +let profile = use_coroutine(cx, |mut rx: UnboundedReciver| async move { let mut server = connect_to_server().await; while let Ok(msg) = rx.next().await { @@ -86,9 +86,9 @@ cx.render(rsx!{ For sufficiently complex apps, we could build a bunch of different useful "services" that loop on channels to update the app. ```rust -let profile = use_coroutine(&cx, profile_service); -let editor = use_coroutine(&cx, editor_service); -let sync = use_coroutine(&cx, sync_service); +let profile = use_coroutine(cx, profile_service); +let editor = use_coroutine(cx, editor_service); +let sync = use_coroutine(cx, sync_service); async fn profile_service(rx: UnboundedReceiver) { // do stuff @@ -109,9 +109,9 @@ We can combine coroutines with Fermi to emulate Redux Toolkit's Thunk system wit static USERNAME: Atom = |_| "default".to_string(); fn app(cx: Scope) -> Element { - let atoms = use_atom_root(&cx); + let atoms = use_atom_root(cx); - use_coroutine(&cx, |rx| sync_service(rx, atoms.clone())); + use_coroutine(cx, |rx| sync_service(rx, atoms.clone())); cx.render(rsx!{ Banner {} @@ -119,7 +119,7 @@ fn app(cx: Scope) -> Element { } fn Banner(cx: Scope) -> Element { - let username = use_read(&cx, USERNAME); + let username = use_read(cx, USERNAME); cx.render(rsx!{ h1 { "Welcome back, {username}" } @@ -158,8 +158,8 @@ To yield values from a coroutine, simply bring in a `UseState` handle and set th ```rust -let sync_status = use_state(&cx, || Status::Launching); -let sync_task = use_coroutine(&cx, |rx: UnboundedReceiver| { +let sync_status = use_state(cx, || Status::Launching); +let sync_task = use_coroutine(cx, |rx: UnboundedReceiver| { to_owned![sync_status]; async move { loop { @@ -176,7 +176,7 @@ Coroutine handles are automatically injected through the context API. `use_corou ```rust fn Child(cx: Scope) -> Element { - let sync_task = use_coroutine_handle::(&cx); + let sync_task = use_coroutine_handle::(cx); sync_task.send(SyncAction::SetUsername); } diff --git a/docs/guide/src/en/best_practices/error_handling.md b/docs/guide/src/en/best_practices/error_handling.md index c9a46553..afbb4541 100644 --- a/docs/guide/src/en/best_practices/error_handling.md +++ b/docs/guide/src/en/best_practices/error_handling.md @@ -56,7 +56,7 @@ The next "best" way of handling errors in Dioxus is to match on the error locall To do this, we simply have an error state built into our component: ```rust -let err = use_state(&cx, || None); +let err = use_state(cx, || None); ``` Whenever we perform an action that generates an error, we'll set that error state. We can then match on the error in a number of ways (early return, return Element, etc). @@ -64,7 +64,7 @@ Whenever we perform an action that generates an error, we'll set that error stat ```rust fn Commandline(cx: Scope) -> Element { - let error = use_state(&cx, || None); + let error = use_state(cx, || None); cx.render(match *error { Some(error) => rsx!( @@ -85,7 +85,7 @@ If you're dealing with a handful of components with minimal nesting, you can jus ```rust fn Commandline(cx: Scope) -> Element { - let error = use_state(&cx, || None); + let error = use_state(cx, || None); if let Some(error) = **error { return cx.render(rsx!{ "An error occured" }); @@ -125,7 +125,7 @@ Then, in our top level component, we want to explicitly handle the possible erro ```rust fn TopLevel(cx: Scope) -> Element { - let error = use_read(&cx, INPUT_ERROR); + let error = use_read(cx, INPUT_ERROR); match error { TooLong => return cx.render(rsx!{ "FAILED: Too long!" }), @@ -139,7 +139,7 @@ Now, whenever a downstream component has an error in its actions, it can simply ```rust fn Commandline(cx: Scope) -> Element { - let set_error = use_set(&cx, INPUT_ERROR); + let set_error = use_set(cx, INPUT_ERROR); cx.render(rsx!{ input { diff --git a/docs/guide/src/en/index.md b/docs/guide/src/en/index.md index 761f1e7d..770be440 100644 --- a/docs/guide/src/en/index.md +++ b/docs/guide/src/en/index.md @@ -6,7 +6,7 @@ Dioxus is a portable, performant, and ergonomic framework for building cross-pla ```rust fn app(cx: Scope) -> Element { - let mut count = use_state(&cx, || 0); + let mut count = use_state(cx, || 0); cx.render(rsx!( h1 { "High-Five counter: {count}" } @@ -48,4 +48,4 @@ Web: Since the web is a fairly mature platform, we expect there to be very littl Desktop: APIs will likely be in flux as we figure out better patterns than our ElectronJS counterpart. -SSR: We don't expect the SSR API to change drastically in the future. \ No newline at end of file +SSR: We don't expect the SSR API to change drastically in the future. diff --git a/docs/guide/src/pt-br/async/use_coroutine.md b/docs/guide/src/pt-br/async/use_coroutine.md index c27878fd..cd7cbff1 100644 --- a/docs/guide/src/pt-br/async/use_coroutine.md +++ b/docs/guide/src/pt-br/async/use_coroutine.md @@ -10,7 +10,7 @@ A configuração básica para corrotinas é o _hook_ `use_coroutine`. A maioria ```rust fn app(cx: Scope) -> Element { - let ws: &UseCoroutine<()> = use_coroutine(&cx, |rx| async move { + let ws: &UseCoroutine<()> = use_coroutine(cx, |rx| async move { // Connect to some sort of service let mut conn = connect_to_ws_server().await; @@ -27,7 +27,7 @@ Para muitos serviços, um _loop_ assíncrono simples lidará com a maioria dos c No entanto, se quisermos desabilitar temporariamente a corrotina, podemos "pausá-la" usando o método `pause` e "retomá-la" usando o método `resume`: ```rust -let sync: &UseCoroutine<()> = use_coroutine(&cx, |rx| async move { +let sync: &UseCoroutine<()> = use_coroutine(cx, |rx| async move { // code for syncing }); @@ -62,7 +62,7 @@ enum ProfileUpdate { SetAge(i32) } -let profile = use_coroutine(&cx, |mut rx: UnboundedReciver| async move { +let profile = use_coroutine(cx, |mut rx: UnboundedReciver| async move { let mut server = connect_to_server().await; while let Ok(msg) = rx.next().await { @@ -85,9 +85,9 @@ cx.render(rsx!{ Para aplicativos suficientemente complexos, poderíamos criar vários "serviços" úteis diferentes que fazem um _loop_ nos canais para atualizar o aplicativo. ```rust -let profile = use_coroutine(&cx, profile_service); -let editor = use_coroutine(&cx, editor_service); -let sync = use_coroutine(&cx, sync_service); +let profile = use_coroutine(cx, profile_service); +let editor = use_coroutine(cx, editor_service); +let sync = use_coroutine(cx, sync_service); async fn profile_service(rx: UnboundedReceiver) { // do stuff @@ -108,9 +108,9 @@ Podemos combinar corrotinas com `Fermi` para emular o sistema `Thunk` do **Redux static USERNAME: Atom = |_| "default".to_string(); fn app(cx: Scope) -> Element { - let atoms = use_atom_root(&cx); + let atoms = use_atom_root(cx); - use_coroutine(&cx, |rx| sync_service(rx, atoms.clone())); + use_coroutine(cx, |rx| sync_service(rx, atoms.clone())); cx.render(rsx!{ Banner {} @@ -118,7 +118,7 @@ fn app(cx: Scope) -> Element { } fn Banner(cx: Scope) -> Element { - let username = use_read(&cx, USERNAME); + let username = use_read(cx, USERNAME); cx.render(rsx!{ h1 { "Welcome back, {username}" } @@ -156,8 +156,8 @@ async fn sync_service(mut rx: UnboundedReceiver, atoms: AtomRoot) { Para obter valores de uma corrotina, basta usar um identificador `UseState` e definir o valor sempre que sua corrotina concluir seu trabalho. ```rust -let sync_status = use_state(&cx, || Status::Launching); -let sync_task = use_coroutine(&cx, |rx: UnboundedReceiver| { +let sync_status = use_state(cx, || Status::Launching); +let sync_task = use_coroutine(cx, |rx: UnboundedReceiver| { to_owned![sync_status]; async move { loop { @@ -174,7 +174,7 @@ Os identificadores de corrotina são injetados automaticamente por meio da API d ```rust fn Child(cx: Scope) -> Element { - let sync_task = use_coroutine_handle::(&cx); + let sync_task = use_coroutine_handle::(cx); sync_task.send(SyncAction::SetUsername); } diff --git a/docs/guide/src/pt-br/best_practices/error_handling.md b/docs/guide/src/pt-br/best_practices/error_handling.md index 52c560b6..93832223 100644 --- a/docs/guide/src/pt-br/best_practices/error_handling.md +++ b/docs/guide/src/pt-br/best_practices/error_handling.md @@ -53,14 +53,14 @@ A próxima "melhor" maneira de lidar com erros no Dioxus é combinar (`match`) o Para fazer isso, simplesmente temos um estado de erro embutido em nosso componente: ```rust -let err = use_state(&cx, || None); +let err = use_state(cx, || None); ``` Sempre que realizarmos uma ação que gere um erro, definiremos esse estado de erro. Podemos então combinar o erro de várias maneiras (retorno antecipado, elemento de retorno etc.). ```rust fn Commandline(cx: Scope) -> Element { - let error = use_state(&cx, || None); + let error = use_state(cx, || None); cx.render(match *error { Some(error) => rsx!( @@ -81,7 +81,7 @@ Se você estiver lidando com alguns componentes com um mínimo de aninhamento, b ```rust fn Commandline(cx: Scope) -> Element { - let error = use_state(&cx, || None); + let error = use_state(cx, || None); if let Some(error) = **error { return cx.render(rsx!{ "An error occured" }); @@ -120,7 +120,7 @@ Então, em nosso componente de nível superior, queremos tratar explicitamente o ```rust fn TopLevel(cx: Scope) -> Element { - let error = use_read(&cx, INPUT_ERROR); + let error = use_read(cx, INPUT_ERROR); match error { TooLong => return cx.render(rsx!{ "FAILED: Too long!" }), @@ -134,7 +134,7 @@ Agora, sempre que um componente _downstream_ tiver um erro em suas ações, ele ```rust fn Commandline(cx: Scope) -> Element { - let set_error = use_set(&cx, INPUT_ERROR); + let set_error = use_set(cx, INPUT_ERROR); cx.render(rsx!{ input { diff --git a/docs/guide/src/pt-br/index.md b/docs/guide/src/pt-br/index.md index dffd7046..121f3ef4 100644 --- a/docs/guide/src/pt-br/index.md +++ b/docs/guide/src/pt-br/index.md @@ -6,7 +6,7 @@ Dioxus é uma estrutura portátil, de alto desempenho e ergonômica para a const ```rust fn app(cx: Scope) -> Element { - let mut count = use_state(&cx, || 0); + let mut count = use_state(cx, || 0); cx.render(rsx!( h1 { "High-Five counter: {count}" } diff --git a/docs/posts/release-0-2-0.md b/docs/posts/release-0-2-0.md index 79a341e9..7aed2fda 100644 --- a/docs/posts/release-0-2-0.md +++ b/docs/posts/release-0-2-0.md @@ -27,7 +27,7 @@ Dioxus is a recently-released library for building interactive user interfaces ( ```rust fn app(cx: Scope) -> Element { - let mut count = use_state(&cx, || 0); + let mut count = use_state(cx, || 0); cx.render(rsx! { h1 { "Count: {count}" } @@ -102,8 +102,8 @@ We're also using hooks to parse the URL parameters and segments so you can inter struct Query { name: String } fn BlogPost(cx: Scope) -> Element { - let post = use_route(&cx).segment("post")?; - let query = use_route(&cx).query::()?; + let post = use_route(cx).segment("post")?; + let query = use_route(cx).query::()?; cx.render(rsx!{ "Viewing post {post}" @@ -128,7 +128,7 @@ static TITLE: Atom<&str> = |_| "Hello"; // Read the value from anywhere in the app, subscribing to any changes fn app(cx: Scope) -> Element { - let title = use_read(&cx, TITLE); + let title = use_read(cx, TITLE); cx.render(rsx!{ h1 { "{title}" } Child {} @@ -137,7 +137,7 @@ fn app(cx: Scope) -> Element { // Set the value from anywhere in the app fn Child(cx: Scope) -> Element { - let set_title = use_set(&cx, TITLE); + let set_title = use_set(cx, TITLE); cx.render(rsx!{ button { onclick: move |_| set_title("goodbye"), @@ -245,7 +245,7 @@ First, we upgraded the `use_future` hook. It now supports dependencies, which le ```rust fn RenderDog(cx: Scope, breed: String) -> Element { - let dog_request = use_future(&cx, (breed,), |(breed,)| async move { + let dog_request = use_future(cx, (breed,), |(breed,)| async move { reqwest::get(format!("https://dog.ceo/api/breed/{}/images/random", breed)) .await .unwrap() @@ -265,7 +265,7 @@ Additionally, we added better support for coroutines. You can now start, stop, r ```rust fn App(cx: Scope) -> Element { - let sync_task = use_coroutine(&cx, |rx| async move { + let sync_task = use_coroutine(cx, |rx| async move { connect_to_server().await; let state = MyState::new(); diff --git a/docs/posts/release.md b/docs/posts/release.md index 80f8a0f4..b40b451c 100644 --- a/docs/posts/release.md +++ b/docs/posts/release.md @@ -28,7 +28,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let mut count = use_state(&cx, || 0); + let mut count = use_state(cx, || 0); cx.render(rsx! { h1 { "Count: {count}" } @@ -138,7 +138,7 @@ struct CardProps { } static Card: Component = |cx| { - let mut count = use_state(&cx, || 0); + let mut count = use_state(cx, || 0); cx.render(rsx!( aside { h2 { "{cx.props.title}" } @@ -191,7 +191,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let mut count = use_state(&cx, || 0); + let mut count = use_state(cx, || 0); cx.render(rsx! { h1 { "Count: {count}" } @@ -260,7 +260,7 @@ Dioxus understands the lifetimes of data borrowed from `Scope`, so you can safel ```rust -let name = use_state(&cx, || "asd"); +let name = use_state(cx, || "asd"); rsx! { div { button { onclick: move |_| name.set("abc") } @@ -274,7 +274,7 @@ Because we know the lifetime of your handlers, we can also expose this to childr ```rust fn app(cx: Scope) -> Element { - let name = use_state(&cx, || "asd"); + let name = use_state(cx, || "asd"); cx.render(rsx!{ Button { name: name } }) diff --git a/docs/router/src/guide/building-a-nest.md b/docs/router/src/guide/building-a-nest.md index 5abe6ede..532af6c3 100644 --- a/docs/router/src/guide/building-a-nest.md +++ b/docs/router/src/guide/building-a-nest.md @@ -10,12 +10,12 @@ Let's create a new ``navbar`` component: fn navbar(cx: Scope) -> Element { cx.render(rsx! { ul { - + } }) } ``` -Our navbar will be a list of links going between our pages. We could always use an HTML anchor element but that would cause our page to unnecessarily reload. Instead we want to use the ``Link`` component provided by Dioxus Router. +Our navbar will be a list of links going between our pages. We could always use an HTML anchor element but that would cause our page to unnecessarily reload. Instead we want to use the ``Link`` component provided by Dioxus Router. The Link component is very similar to the Route component. It takes a path and an element. Add the Link component into your use statement and then add some links: ```rs @@ -38,7 +38,7 @@ fn navbar(cx: Scope) -> Element { } ``` >By default, the Link component only works for links within your application. To link to external sites, add the ``external: true`` property. ->```rs +>```rs >Link { to: "https://github.com", external: true, "GitHub"} >``` @@ -66,7 +66,7 @@ We want to store our blogs in a database and load them as needed. This'll help p We could utilize a search page that loads a blog when clicked but then our users won't be able to share our blogs easily. This is where URL parameters come in. And finally, we also want our site to tell users they are on a blog page whenever the URL starts with``/blog``. The path to our blog will look like ``/blog/myBlogPage``. ``myBlogPage`` being the URL parameter. -Dioxus Router uses the ``:name`` pattern so our route will look like ``/blog/:post``. +Dioxus Router uses the ``:name`` pattern so our route will look like ``/blog/:post``. First, lets tell users when they are on a blog page. Add a new route in your app component. ```rs @@ -77,7 +77,7 @@ fn app(cx: Scope) -> Element { self::navbar {} Route { to: "/", self::homepage {}} // NEW - Route { + Route { to: "/blog", } Route { to: "", self::page_not_found {}} @@ -93,7 +93,7 @@ fn app(cx: Scope) -> Element { p { "-- Dioxus Blog --" } self::navbar {} Route { to: "/", self::homepage {}} - Route { + Route { to: "/blog", Route { to: "/:post", "This is my blog post!" } // NEW } @@ -109,7 +109,7 @@ fn app(cx: Scope) -> Element { Router { self::navbar {} Route { to: "/", self::homepage {}} - Route { + Route { to: "/blog", p { "-- Dioxus Blog --" } // MOVED Route { to: "/:post", "This is my blog post!" } @@ -119,7 +119,7 @@ fn app(cx: Scope) -> Element { }) } ``` -Now our ``-- Dioxus Blog --`` text will be displayed whenever a user is on a path that starts with ``/blog``. Displaying content in a way that is page-agnostic is useful when building navigation menus, footers, and similar. +Now our ``-- Dioxus Blog --`` text will be displayed whenever a user is on a path that starts with ``/blog``. Displaying content in a way that is page-agnostic is useful when building navigation menus, footers, and similar. All that's left is to handle our URL parameter. We will begin by creating a ``get_blog_post`` function. In a real site, this function would call an API endpoint to get a blog post from the database. However, that is out of the scope of this guide so we will be utilizing static text. ```rs @@ -153,7 +153,7 @@ use dioxus::{ ... fn blog_post(cx: Scope) -> Element { - let route = use_route(&cx); // NEW + let route = use_route(cx); // NEW let blog_text = ""; cx.render(rsx! { @@ -165,7 +165,7 @@ Dioxus Router provides built in methods to extract information from a route. We The ``segment`` method also parses the parameter into any type for us. We'll use a match expression that handles a parsing error and on success, uses our helper function to grab the blog post. ```rs fn blog_post(cx: Scope) -> Element { - let route = use_route(&cx); + let route = use_route(cx); // NEW let blog_text = match route.segment::("post").unwrap() { @@ -198,4 +198,4 @@ fn app(cx: Scope) -> Element { That's it! If you head to ``/blog/foo`` you should see ``Welcome to the foo blog post!``. ### Conclusion -In this chapter we utilized Dioxus Router's Link, URL Parameter, and ``use_route`` functionality to build the blog portion of our application. In the next and final chapter, we will go over the ``Redirect`` component to redirect non-authorized users to another page. \ No newline at end of file +In this chapter we utilized Dioxus Router's Link, URL Parameter, and ``use_route`` functionality to build the blog portion of our application. In the next and final chapter, we will go over the ``Redirect`` component to redirect non-authorized users to another page. diff --git a/examples/all_events.rs b/examples/all_events.rs index 493df0c8..594a736d 100644 --- a/examples/all_events.rs +++ b/examples/all_events.rs @@ -41,7 +41,7 @@ const RECT_STYLE: &str = r#" "#; fn app(cx: Scope) -> Element { - let events = use_ref(&cx, std::collections::VecDeque::new); + let events = use_ref(cx, std::collections::VecDeque::new); let log_event = move |event: Event| { let mut events = events.write(); diff --git a/examples/calculator.rs b/examples/calculator.rs index 93e29801..bf183ba6 100644 --- a/examples/calculator.rs +++ b/examples/calculator.rs @@ -19,7 +19,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let val = use_state(&cx, || String::from("0")); + let val = use_state(cx, || String::from("0")); let input_digit = move |num: u8| { if val.get() == "0" { diff --git a/examples/crm.rs b/examples/crm.rs index 1943ed97..72401017 100644 --- a/examples/crm.rs +++ b/examples/crm.rs @@ -16,10 +16,10 @@ pub struct Client { } fn app(cx: Scope) -> Element { - let clients = use_ref(&cx, || vec![] as Vec); - let firstname = use_state(&cx, String::new); - let lastname = use_state(&cx, String::new); - let description = use_state(&cx, String::new); + let clients = use_ref(cx, || vec![] as Vec); + let firstname = use_state(cx, String::new); + let lastname = use_state(cx, String::new); + let description = use_state(cx, String::new); cx.render(rsx!( body { diff --git a/examples/custom_element.rs b/examples/custom_element.rs index 19bfa0fd..87b1fac3 100644 --- a/examples/custom_element.rs +++ b/examples/custom_element.rs @@ -16,7 +16,7 @@ fn main() { } fn app(cx: Scope) -> Element { - // let nf = NodeFactory::new(&cx); + // let nf = NodeFactory::new(cx); // let mut attrs = dioxus::core::exports::bumpalo::collections::Vec::new_in(nf.bump()); diff --git a/examples/disabled.rs b/examples/disabled.rs index f89aafe5..5be75b8b 100644 --- a/examples/disabled.rs +++ b/examples/disabled.rs @@ -5,7 +5,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let disabled = use_state(&cx, || false); + let disabled = use_state(cx, || false); cx.render(rsx! { div { diff --git a/examples/error_handle.rs b/examples/error_handle.rs index 5c64915c..b4a6dbb0 100644 --- a/examples/error_handle.rs +++ b/examples/error_handle.rs @@ -5,7 +5,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let val = use_state(&cx, || "0.0001"); + let val = use_state(cx, || "0.0001"); let num = match val.parse::() { Err(_) => return cx.render(rsx!("Parsing failed")), diff --git a/examples/eval.rs b/examples/eval.rs index ad7a493f..c0dda3e0 100644 --- a/examples/eval.rs +++ b/examples/eval.rs @@ -5,8 +5,8 @@ fn main() { } fn app(cx: Scope) -> Element { - let script = use_state(&cx, String::new); - let eval = dioxus_desktop::use_eval(&cx); + let script = use_state(cx, String::new); + let eval = dioxus_desktop::use_eval(cx); cx.render(rsx! { div { diff --git a/examples/fermi.rs b/examples/fermi.rs index de5fb6d6..babe3e02 100644 --- a/examples/fermi.rs +++ b/examples/fermi.rs @@ -10,7 +10,7 @@ fn main() { static NAME: Atom = |_| "world".to_string(); fn app(cx: Scope) -> Element { - let name = use_read(&cx, NAME); + let name = use_read(cx, NAME); cx.render(rsx! { div { "hello {name}!" } @@ -20,7 +20,7 @@ fn app(cx: Scope) -> Element { } fn Child(cx: Scope) -> Element { - let set_name = use_set(&cx, NAME); + let set_name = use_set(cx, NAME); cx.render(rsx! { button { @@ -33,7 +33,7 @@ fn Child(cx: Scope) -> Element { static NAMES: AtomRef> = |_| vec!["world".to_string()]; fn ChildWithRef(cx: Scope) -> Element { - let names = use_atom_ref(&cx, NAMES); + let names = use_atom_ref(cx, NAMES); cx.render(rsx! { div { diff --git a/examples/file_explorer.rs b/examples/file_explorer.rs index 16b3b5fa..64173ad1 100644 --- a/examples/file_explorer.rs +++ b/examples/file_explorer.rs @@ -19,7 +19,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let files = use_ref(&cx, Files::new); + let files = use_ref(cx, Files::new); cx.render(rsx! { div { diff --git a/examples/framework_benchmark.rs b/examples/framework_benchmark.rs index df5884b2..7e7a320a 100644 --- a/examples/framework_benchmark.rs +++ b/examples/framework_benchmark.rs @@ -32,8 +32,8 @@ impl Label { } fn app(cx: Scope) -> Element { - let items = use_ref(&cx, Vec::new); - let selected = use_state(&cx, || None); + let items = use_ref(cx, Vec::new); + let selected = use_state(cx, || None); cx.render(rsx! { div { class: "container", diff --git a/examples/hydration.rs b/examples/hydration.rs index b525a3fb..ed43a9f7 100644 --- a/examples/hydration.rs +++ b/examples/hydration.rs @@ -20,7 +20,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let val = use_state(&cx, || 0); + let val = use_state(cx, || 0); cx.render(rsx! { div { diff --git a/examples/inlineprops.rs b/examples/inlineprops.rs index 786714a2..8c626d34 100644 --- a/examples/inlineprops.rs +++ b/examples/inlineprops.rs @@ -28,7 +28,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let state = use_state(&cx, || 1); + let state = use_state(cx, || 1); cx.render(rsx! { div { diff --git a/examples/pattern_model.rs b/examples/pattern_model.rs index 9d835d25..a6c35d17 100644 --- a/examples/pattern_model.rs +++ b/examples/pattern_model.rs @@ -36,7 +36,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let state = use_ref(&cx, Calculator::new); + let state = use_ref(cx, Calculator::new); cx.render(rsx! { style { include_str!("./assets/calculator.css") } diff --git a/examples/pattern_reducer.rs b/examples/pattern_reducer.rs index 6778324a..6f7e16f6 100644 --- a/examples/pattern_reducer.rs +++ b/examples/pattern_reducer.rs @@ -15,7 +15,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let state = use_state(&cx, PlayerState::new); + let state = use_state(cx, PlayerState::new); cx.render(rsx!( div { diff --git a/examples/readme.rs b/examples/readme.rs index 59816357..f4668488 100644 --- a/examples/readme.rs +++ b/examples/readme.rs @@ -9,7 +9,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let mut count = use_state(&cx, || 0); + let mut count = use_state(cx, || 0); cx.render(rsx! { h1 { "High-Five counter: {count}" } diff --git a/examples/router.rs b/examples/router.rs index a4118111..5766b8e1 100644 --- a/examples/router.rs +++ b/examples/router.rs @@ -30,7 +30,7 @@ fn app(cx: Scope) -> Element { } fn BlogPost(cx: Scope) -> Element { - let post = dioxus_router::use_route(&cx).last_segment().unwrap(); + let post = dioxus_router::use_route(cx).last_segment().unwrap(); cx.render(rsx! { div { @@ -46,9 +46,9 @@ struct Query { } fn User(cx: Scope) -> Element { - let post = dioxus_router::use_route(&cx).last_segment().unwrap(); + let post = dioxus_router::use_route(cx).last_segment().unwrap(); - let query = dioxus_router::use_route(&cx) + let query = dioxus_router::use_route(cx) .query::() .unwrap_or(Query { bold: false }); diff --git a/examples/rsx_compile_fail.rs b/examples/rsx_compile_fail.rs index 37521960..40bad709 100644 --- a/examples/rsx_compile_fail.rs +++ b/examples/rsx_compile_fail.rs @@ -13,14 +13,14 @@ fn main() { } fn example(cx: Scope) -> Element { - let items = use_state(&cx, || { + let items = use_state(cx, || { vec![Thing { a: "asd".to_string(), b: 10, }] }); - let things = use_ref(&cx, || { + let things = use_ref(cx, || { vec![Thing { a: "asd".to_string(), b: 10, @@ -28,7 +28,7 @@ fn example(cx: Scope) -> Element { }); let things_list = things.read(); - let mything = use_ref(&cx, || Some(String::from("asd"))); + let mything = use_ref(cx, || Some(String::from("asd"))); let mything_read = mything.read(); cx.render(rsx!( diff --git a/examples/rsx_usage.rs b/examples/rsx_usage.rs index 99598479..fb7bb623 100644 --- a/examples/rsx_usage.rs +++ b/examples/rsx_usage.rs @@ -200,7 +200,7 @@ fn app(cx: Scope) -> Element { // helper functions // Anything that implements IntoVnode can be dropped directly into Rsx - helper(&cx, "hello world!") + helper(cx, "hello world!") // Strings can be supplied directly String::from("Hello world!") diff --git a/examples/ssr.rs b/examples/ssr.rs index 0bdebc41..bac3759d 100644 --- a/examples/ssr.rs +++ b/examples/ssr.rs @@ -2,16 +2,13 @@ //! //! This example shows how we can render the Dioxus Virtualdom using SSR. -use std::fmt::Write; - use dioxus::prelude::*; -use dioxus_ssr::config::Config; fn main() { // We can render VirtualDoms let mut vdom = VirtualDom::new(app); let _ = vdom.rebuild(); - println!("{}", dioxus_ssr::render_vdom(&vdom)); + println!("{}", dioxus_ssr::render(&vdom)); // Or we can render rsx! calls themselves println!( @@ -24,17 +21,12 @@ fn main() { ); // We can configure the SSR rendering to add ids for rehydration - println!( - "{}", - dioxus_ssr::render_vdom_cfg(&vdom, Config::default().pre_render(true)) - ); + println!("{}", dioxus_ssr::pre_render(&vdom)); - // We can even render as a writer + // We can render to a buf directly too let mut file = String::new(); - let _ = file.write_fmt(format_args!( - "{}", - dioxus_ssr::SsrRender::default().render_vdom(&vdom) - )); + let mut renderer = dioxus_ssr::Renderer::default(); + renderer.render_to(&mut file, &vdom).unwrap(); println!("{}", file); } diff --git a/examples/suspense.rs b/examples/suspense.rs index c1a0e4c0..dbdad2eb 100644 --- a/examples/suspense.rs +++ b/examples/suspense.rs @@ -53,7 +53,7 @@ fn app(cx: Scope) -> Element { /// Suspense is achieved my moving the future into only the component that /// actually renders the data. fn Doggo(cx: Scope) -> Element { - let fut = use_future(&cx, (), |_| async move { + let fut = use_future(cx, (), |_| async move { reqwest::get("https://dog.ceo/api/breeds/image/random/") .await .unwrap() diff --git a/examples/svg.rs b/examples/svg.rs index 631a3803..829a559a 100644 --- a/examples/svg.rs +++ b/examples/svg.rs @@ -7,7 +7,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let val = use_state(&cx, || 5); + let val = use_state(cx, || 5); cx.render(rsx! { div { diff --git a/examples/tasks.rs b/examples/tasks.rs index 7c192a59..874666c2 100644 --- a/examples/tasks.rs +++ b/examples/tasks.rs @@ -10,9 +10,9 @@ fn main() { } fn app(cx: Scope) -> Element { - let count = use_state(&cx, || 0); + let count = use_state(cx, || 0); - use_future(&cx, (), move |_| { + use_future(cx, (), move |_| { let mut count = count.clone(); async move { loop { diff --git a/examples/textarea.rs b/examples/textarea.rs index 26283b23..b27a9c99 100644 --- a/examples/textarea.rs +++ b/examples/textarea.rs @@ -7,7 +7,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let model = use_state(&cx, || String::from("asd")); + let model = use_state(cx, || String::from("asd")); println!("{}", model); diff --git a/examples/window_event.rs b/examples/window_event.rs index cd752fa1..44ddebec 100644 --- a/examples/window_event.rs +++ b/examples/window_event.rs @@ -12,15 +12,15 @@ fn main() { } fn app(cx: Scope) -> Element { - let window = dioxus_desktop::use_window(&cx); + let window = dioxus_desktop::use_window(cx); // if you want to make window fullscreen, you need close the resizable. // window.set_fullscreen(true); // window.set_resizable(false); - let fullscreen = use_state(&cx, || false); - let always_on_top = use_state(&cx, || false); - let decorations = use_state(&cx, || false); + let fullscreen = use_state(cx, || false); + let always_on_top = use_state(cx, || false); + let decorations = use_state(cx, || false); cx.render(rsx!( link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" } diff --git a/examples/window_zoom.rs b/examples/window_zoom.rs index d312b0af..b7c19089 100644 --- a/examples/window_zoom.rs +++ b/examples/window_zoom.rs @@ -6,9 +6,9 @@ fn main() { } fn app(cx: Scope) -> Element { - let window = use_window(&cx); + let window = use_window(cx); - let level = use_state(&cx, || 1.0); + let level = use_state(cx, || 1.0); cx.render(rsx! { input { r#type: "number", diff --git a/examples/xss_safety.rs b/examples/xss_safety.rs index 2d5eba20..5272d661 100644 --- a/examples/xss_safety.rs +++ b/examples/xss_safety.rs @@ -9,7 +9,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let contents = use_state(&cx, || { + let contents = use_state(cx, || { String::from("") }); diff --git a/notes/README.md b/notes/README.md index a182191a..2e5a03b1 100644 --- a/notes/README.md +++ b/notes/README.md @@ -233,7 +233,7 @@ use hooks to define state and modify it from within listeners. ```rust, ignore fn app(cx: Scope) -> Element { - let name = use_state(&cx, || "world"); + let name = use_state(cx, || "world"); render!("hello {name}!") } @@ -280,7 +280,7 @@ fn main() { } fn App(cx: Scope) -> Element { - let count = use_state(&cx, || 0); + let count = use_state(cx, || 0); cx.render(rsx!( div { "Count: {count}" } diff --git a/notes/README/ZH_CN.md b/notes/README/ZH_CN.md index 07bcdee5..8b1e6185 100644 --- a/notes/README/ZH_CN.md +++ b/notes/README/ZH_CN.md @@ -54,7 +54,7 @@ Dioxus 是一个可移植的、高性能的、符合人体工程学的框架, ```rust fn app(cx: Scope) -> Element { - let mut count = use_state(&cx, || 0); + let mut count = use_state(cx, || 0); cx.render(rsx! { h1 { "High-Five counter: {count}" } diff --git a/notes/SOLVEDPROBLEMS.md b/notes/SOLVEDPROBLEMS.md index c74b4117..b978c923 100644 --- a/notes/SOLVEDPROBLEMS.md +++ b/notes/SOLVEDPROBLEMS.md @@ -406,8 +406,8 @@ enum Patch { ``` ```rust -let node_ref = use_node_ref(&cx); -use_effect(&cx, || { +let node_ref = use_node_ref(cx); +use_effect(cx, || { }, []); div { ref: node_ref, diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 71d615a4..0c175136 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -21,9 +21,12 @@ pub fn use_window(cx: &ScopeState) -> &DesktopContext { /// Get a closure that executes any JavaScript in the WebView context. pub fn use_eval(cx: &ScopeState) -> &Rc { - let desktop = use_window(cx).clone(); + let desktop = use_window(cx); - &*cx.use_hook(|| Rc::new(move |script| desktop.eval(script)) as Rc) + &*cx.use_hook(|| { + let desktop = desktop.clone(); + Rc::new(move |script| desktop.eval(script)) + } as Rc) } /// An imperative interface to the current window. diff --git a/packages/fermi/README.md b/packages/fermi/README.md index 5d80f2ff..711b1a43 100644 --- a/packages/fermi/README.md +++ b/packages/fermi/README.md @@ -44,7 +44,7 @@ From anywhere in our app, we can read our the value of our atom: ```rust, ignore fn NameCard(cx: Scope) -> Element { - let name = use_read(&cx, NAME); + let name = use_read(cx, NAME); cx.render(rsx!{ h1 { "Hello, {name}"} }) } ``` @@ -53,7 +53,7 @@ We can also set the value of our atom, also from anywhere in our app: ```rust, ignore fn NameCard(cx: Scope) -> Element { - let set_name = use_set(&cx, NAME); + let set_name = use_set(cx, NAME); cx.render(rsx!{ button { onclick: move |_| set_name("Fermi"), diff --git a/packages/fermi/src/hooks/state.rs b/packages/fermi/src/hooks/state.rs index 96315044..15310cff 100644 --- a/packages/fermi/src/hooks/state.rs +++ b/packages/fermi/src/hooks/state.rs @@ -19,7 +19,7 @@ use std::{ /// static COUNT: Atom = |_| 0; /// /// fn Example(cx: Scope) -> Element { -/// let mut count = use_atom_state(&cx, COUNT); +/// let mut count = use_atom_state(cx, COUNT); /// /// cx.render(rsx! { /// div { @@ -74,7 +74,7 @@ impl AtomState { /// /// ```rust, ignore /// fn component(cx: Scope) -> Element { - /// let count = use_state(&cx, || 0); + /// let count = use_state(cx, || 0); /// cx.spawn({ /// let set_count = count.to_owned(); /// async move { @@ -101,7 +101,7 @@ impl AtomState { /// /// ```rust, ignore /// fn component(cx: Scope) -> Element { - /// let value = use_state(&cx, || 0); + /// let value = use_state(cx, || 0); /// /// rsx!{ /// Component { @@ -128,7 +128,7 @@ impl AtomState { /// # use dioxus_core::prelude::*; /// # use dioxus_hooks::*; /// fn component(cx: Scope) -> Element { - /// let value = use_state(&cx, || 0); + /// let value = use_state(cx, || 0); /// /// // to increment the value /// value.modify(|v| v + 1); @@ -168,7 +168,7 @@ impl AtomState { /// # use dioxus_core::prelude::*; /// # use dioxus_hooks::*; /// fn component(cx: Scope) -> Element { - /// let value = use_state(&cx, || 0); + /// let value = use_state(cx, || 0); /// /// let as_rc = value.get(); /// assert_eq!(as_rc.as_ref(), &0); @@ -190,7 +190,7 @@ impl AtomState { /// /// ```rust, ignore /// fn component(cx: Scope) -> Element { - /// let count = use_state(&cx, || 0); + /// let count = use_state(cx, || 0); /// cx.spawn({ /// let count = count.to_owned(); /// async move { @@ -220,7 +220,7 @@ impl AtomState { /// # Examples /// /// ```ignore - /// let val = use_state(&cx, || 0); + /// let val = use_state(cx, || 0); /// /// val.with_mut(|v| *v = 1); /// ``` @@ -243,7 +243,7 @@ impl AtomState { /// # Examples /// /// ```ignore - /// let val = use_state(&cx, || 0); + /// let val = use_state(cx, || 0); /// /// *val.make_mut() += 1; /// ``` diff --git a/packages/hooks/README.md b/packages/hooks/README.md index 18133e40..14c0e420 100644 --- a/packages/hooks/README.md +++ b/packages/hooks/README.md @@ -15,8 +15,8 @@ You can always use it "normally" with the `split` method: ```rust // Rusty-smart-pointer usage: -let value = use_state(&cx, || 10); +let value = use_state(cx, || 10); // "Classic" usage: -let (value, set_value) = use_state(&cx, || 0).split(); +let (value, set_value) = use_state(cx, || 0).split(); ``` diff --git a/packages/hooks/src/lib.rs b/packages/hooks/src/lib.rs index 9feac8f1..ceafc218 100644 --- a/packages/hooks/src/lib.rs +++ b/packages/hooks/src/lib.rs @@ -5,7 +5,7 @@ /// /// /// ```ignore -/// let (data) = use_ref(&cx, || {}); +/// let (data) = use_ref(cx, || {}); /// /// let handle_thing = move |_| { /// to_owned![data] diff --git a/packages/hooks/src/usecollection.rs b/packages/hooks/src/usecollection.rs index 0eed35b3..b303376b 100644 --- a/packages/hooks/src/usecollection.rs +++ b/packages/hooks/src/usecollection.rs @@ -16,7 +16,7 @@ This is moderately efficient because the fields of the map are moved, but the da However, if you used similar approach with Dioxus: ```rust -let (map, set_map) = use_state(&cx, || HashMap::new()); +let (map, set_map) = use_state(cx, || HashMap::new()); set_map({ let mut newmap = map.clone(); newmap.set(key, value); diff --git a/packages/hooks/src/usecoroutine.rs b/packages/hooks/src/usecoroutine.rs index ec947202..f65d0b0e 100644 --- a/packages/hooks/src/usecoroutine.rs +++ b/packages/hooks/src/usecoroutine.rs @@ -44,7 +44,7 @@ use crate::{use_context, use_context_provider}; /// Stop, /// } /// -/// let chat_client = use_coroutine(&cx, |rx: UnboundedReceiver| async move { +/// let chat_client = use_coroutine(cx, |rx: UnboundedReceiver| async move { /// while let Some(action) = rx.next().await { /// match action { /// Action::Start => {} @@ -119,15 +119,15 @@ mod tests { use futures_util::StreamExt; fn app(cx: Scope, name: String) -> Element { - let task = use_coroutine(&cx, |mut rx: UnboundedReceiver| async move { + let task = use_coroutine(cx, |mut rx: UnboundedReceiver| async move { while let Some(msg) = rx.next().await { println!("got message: {}", msg); } }); - let task2 = use_coroutine(&cx, view_task); + let task2 = use_coroutine(cx, view_task); - let task3 = use_coroutine(&cx, |rx| complex_task(rx, 10)); + let task3 = use_coroutine(cx, |rx| complex_task(rx, 10)); todo!() } diff --git a/packages/hooks/src/useeffect.rs b/packages/hooks/src/useeffect.rs index dd062587..423e5bc2 100644 --- a/packages/hooks/src/useeffect.rs +++ b/packages/hooks/src/useeffect.rs @@ -17,7 +17,7 @@ use crate::UseFutureDep; /// /// #[inline_props] /// fn app(cx: Scope, name: &str) -> Element { -/// use_effect(&cx, (name,), |(name,)| async move { +/// use_effect(cx, (name,), |(name,)| async move { /// set_title(name); /// })) /// } @@ -72,17 +72,17 @@ mod tests { fn app(cx: Scope) -> Element { // should only ever run once - use_effect(&cx, (), |_| async move { + use_effect(cx, (), |_| async move { // }); // runs when a is changed - use_effect(&cx, (&cx.props.a,), |(a,)| async move { + use_effect(cx, (cx.props.a,), |(a,)| async move { // }); // runs when a or b is changed - use_effect(&cx, (&cx.props.a, &cx.props.b), |(a, b)| async move { + use_effect(cx, (cx.props.a, &cx.props.b), |(a, b)| async move { // }); diff --git a/packages/hooks/src/usefuture.rs b/packages/hooks/src/usefuture.rs index df34a643..efea87f4 100644 --- a/packages/hooks/src/usefuture.rs +++ b/packages/hooks/src/usefuture.rs @@ -319,10 +319,10 @@ mod tests { let fut = use_future(cx, (), |_| async move {}); // runs when a is changed - let fut = use_future(cx, (&cx.props.a,), |(a,)| async move {}); + let fut = use_future(cx, (cx.props.a,), |(a,)| async move {}); // runs when a or b is changed - let fut = use_future(cx, (&cx.props.a, &cx.props.b), |(a, b)| async move { 123 }); + let fut = use_future(cx, (cx.props.a, &cx.props.b), |(a, b)| async move { 123 }); let a = use_future!(cx, || async move { // do the thing! diff --git a/packages/hooks/src/usestate.rs b/packages/hooks/src/usestate.rs index fe9f566b..2e1aa729 100644 --- a/packages/hooks/src/usestate.rs +++ b/packages/hooks/src/usestate.rs @@ -19,7 +19,7 @@ use std::{ /// /// ```ignore /// const Example: Component = |cx| { -/// let count = use_state(&cx, || 0); +/// let count = use_state(cx, || 0); /// /// cx.render(rsx! { /// div { @@ -92,7 +92,7 @@ impl UseState { /// /// ```rust, ignore /// fn component(cx: Scope) -> Element { - /// let count = use_state(&cx, || 0); + /// let count = use_state(cx, || 0); /// cx.spawn({ /// let set_count = count.to_owned(); /// async move { @@ -119,7 +119,7 @@ impl UseState { /// /// ```rust, ignore /// fn component(cx: Scope) -> Element { - /// let value = use_state(&cx, || 0); + /// let value = use_state(cx, || 0); /// /// rsx!{ /// Component { @@ -144,7 +144,7 @@ impl UseState { /// # use dioxus_core::prelude::*; /// # use dioxus_hooks::*; /// fn component(cx: Scope) -> Element { - /// let value = use_state(&cx, || 0); + /// let value = use_state(cx, || 0); /// /// // to increment the value /// value.modify(|v| v + 1); @@ -185,7 +185,7 @@ impl UseState { /// # use dioxus_core::prelude::*; /// # use dioxus_hooks::*; /// fn component(cx: Scope) -> Element { - /// let value = use_state(&cx, || 0); + /// let value = use_state(cx, || 0); /// /// let as_rc = value.get(); /// assert_eq!(as_rc.as_ref(), &0); @@ -207,7 +207,7 @@ impl UseState { /// /// ```rust, ignore /// fn component(cx: Scope) -> Element { - /// let count = use_state(&cx, || 0); + /// let count = use_state(cx, || 0); /// cx.spawn({ /// let count = count.to_owned(); /// async move { @@ -237,7 +237,7 @@ impl UseState { /// # Examples /// /// ```rust, ignore - /// let val = use_state(&cx, || 0); + /// let val = use_state(cx, || 0); /// /// val.with_mut(|v| *v = 1); /// ``` @@ -269,7 +269,7 @@ impl UseState { /// # Examples /// /// ```rust, ignore - /// let val = use_state(&cx, || 0); + /// let val = use_state(cx, || 0); /// /// *val.make_mut() += 1; /// ``` @@ -448,7 +448,7 @@ impl + Copy> std::ops::DivAssign for UseState { fn api_makes_sense() { #[allow(unused)] fn app(cx: Scope) -> Element { - let val = use_state(&cx, || 0); + let val = use_state(cx, || 0); val.set(0); val.modify(|v| v + 1); diff --git a/packages/interpreter/src/bindings.rs b/packages/interpreter/src/bindings.rs index 40da394d..d028b8d3 100644 --- a/packages/interpreter/src/bindings.rs +++ b/packages/interpreter/src/bindings.rs @@ -2,7 +2,7 @@ use js_sys::Function; use wasm_bindgen::prelude::*; -use web_sys::{Element, Node}; +use web_sys::Element; #[wasm_bindgen(module = "/src/interpreter.js")] extern "C" { @@ -18,7 +18,7 @@ extern "C" { pub fn MountToRoot(this: &Interpreter); #[wasm_bindgen(method)] - pub fn AppendChildren(this: &Interpreter, m: u32); + pub fn AppendChildren(this: &Interpreter, m: u32, id: u32); #[wasm_bindgen(method)] pub fn AssignId(this: &Interpreter, path: &[u8], id: u32); diff --git a/packages/liveview/README.md b/packages/liveview/README.md index 00a8ce2d..6cdd57dc 100644 --- a/packages/liveview/README.md +++ b/packages/liveview/README.md @@ -40,7 +40,7 @@ async fn order_shoes(mut req: WebsocketRequest) -> Response { } fn App(cx: Scope) -> Element { - let mut count = use_state(&cx, || 0); + let mut count = use_state(cx, || 0); cx.render(rsx!( button { onclick: move |_| count += 1, "Incr" } button { onclick: move |_| count -= 1, "Decr" } diff --git a/packages/liveview/src/events.rs b/packages/liveview/src/events.rs index 874d8081..2c5f97cc 100644 --- a/packages/liveview/src/events.rs +++ b/packages/liveview/src/events.rs @@ -6,7 +6,7 @@ use std::any::Any; use std::sync::Arc; use dioxus_core::ElementId; -use dioxus_html::event_bubbles; +// use dioxus_html::event_bubbles; use dioxus_html::events::*; #[derive(serde::Serialize, serde::Deserialize)] @@ -29,7 +29,7 @@ struct ImEvent { contents: serde_json::Value, } -pub fn trigger_from_serialized(val: serde_json::Value) -> () { +pub fn trigger_from_serialized(_val: serde_json::Value) { todo!() // let ImEvent { // event, diff --git a/packages/router/examples/simple.rs b/packages/router/examples/simple.rs index 84b4f6d9..5256f255 100644 --- a/packages/router/examples/simple.rs +++ b/packages/router/examples/simple.rs @@ -36,7 +36,7 @@ fn BlogList(cx: Scope) -> Element { } fn BlogPost(cx: Scope) -> Element { - let id = use_route(&cx).segment("id")?; + let id = use_route(cx).segment("id")?; log::trace!("rendering blog post {}", id); diff --git a/packages/router/tests/web_router.rs b/packages/router/tests/web_router.rs index 8987ef3b..3d6d05d1 100644 --- a/packages/router/tests/web_router.rs +++ b/packages/router/tests/web_router.rs @@ -47,7 +47,7 @@ fn simple_test() { } fn BlogPost(cx: Scope) -> Element { - let _id = use_route(&cx).parse_segment::("id")?; + let _id = use_route(cx).parse_segment::("id")?; cx.render(rsx! { div { diff --git a/packages/router/usage.md b/packages/router/usage.md index 5fd5456d..3e4d9b59 100644 --- a/packages/router/usage.md +++ b/packages/router/usage.md @@ -89,7 +89,7 @@ You must provide a valid URL `{scheme}://{?authority}/{?path}`. ```rust Router { - initial_url: "https://dioxuslab.com/blog", // Set the initial url. + initial_url: "https://dioxuslab.com/blog", // Set the initial url. Link { to: "/", "Home" }, Link { to: "/blog", "Blog" }, // The router will render this route. } @@ -109,7 +109,7 @@ For any route, you can get a handle the current route with the `use_route` hook. ```rust fn Title(cx: Scope) -> Element { - let route = use_route(&cx); + let route = use_route(cx); assert_eq!(route.segments(), &["dogs", "breeds", "yorkie", "hugo"]); @@ -130,7 +130,7 @@ Router { } fn BlogPost(cx: Scope) -> Element { - let route = use_route(&cx); + let route = use_route(cx); match route.segment("post").and_then(parse) { Some(post) => cx.render(rsx!{ div { "Post {post}" } }) @@ -168,7 +168,7 @@ Listeners can also be attached downstream in your app with the `RouteListener` h ```rust fn TitleCard(cx: Scope) -> Element { - let (title, set_title) = use_state(&cx, || "First"); + let (title, set_title) = use_state(cx, || "First"); cx.render(rsx!{ h1 { "render {title}" } diff --git a/packages/tui/benches/update.rs b/packages/tui/benches/update.rs index f122ce8f..b1fb622e 100644 --- a/packages/tui/benches/update.rs +++ b/packages/tui/benches/update.rs @@ -41,7 +41,7 @@ struct BoxProps { } #[allow(non_snake_case)] fn Box(cx: Scope) -> Element { - let count = use_state(&cx, || 0); + let count = use_state(cx, || 0); let x = cx.props.x * 2; let y = cx.props.y * 2; @@ -70,8 +70,8 @@ struct GridProps { #[allow(non_snake_case)] fn Grid(cx: Scope) -> Element { let size = cx.props.size; - let count = use_state(&cx, || 0); - let counts = use_ref(&cx, || vec![0; size * size]); + let count = use_state(cx, || 0); + let counts = use_ref(cx, || vec![0; size * size]); let ctx: &TuiContext = cx.consume_context().unwrap(); if *count.get() + 1 >= (size * size) { diff --git a/packages/tui/examples/tui_all_events.rs b/packages/tui/examples/tui_all_events.rs index 6995cf39..483e9afd 100644 --- a/packages/tui/examples/tui_all_events.rs +++ b/packages/tui/examples/tui_all_events.rs @@ -27,7 +27,7 @@ enum Event { const MAX_EVENTS: usize = 8; fn app(cx: Scope) -> Element { - let events = use_ref(&cx, Vec::new); + let events = use_ref(cx, Vec::new); let events_lock = events.read(); let first_index = events_lock.len().saturating_sub(MAX_EVENTS); diff --git a/packages/tui/examples/tui_border.rs b/packages/tui/examples/tui_border.rs index 1afa11b5..af2b8158 100644 --- a/packages/tui/examples/tui_border.rs +++ b/packages/tui/examples/tui_border.rs @@ -5,7 +5,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let radius = use_state(&cx, || 0); + let radius = use_state(cx, || 0); cx.render(rsx! { div { diff --git a/packages/tui/examples/tui_buttons.rs b/packages/tui/examples/tui_buttons.rs index 852dd1d9..f40a8843 100644 --- a/packages/tui/examples/tui_buttons.rs +++ b/packages/tui/examples/tui_buttons.rs @@ -13,8 +13,8 @@ struct ButtonProps { #[allow(non_snake_case)] fn Button(cx: Scope) -> Element { - let toggle = use_state(&cx, || false); - let hovered = use_state(&cx, || false); + let toggle = use_state(cx, || false); + let hovered = use_state(cx, || false); let hue = cx.props.color_offset % 255; let saturation = if *toggle.get() { 50 } else { 25 } + if *hovered.get() { 50 } else { 25 }; diff --git a/packages/tui/examples/tui_colorpicker.rs b/packages/tui/examples/tui_colorpicker.rs index e2c16d5b..edbcbddd 100644 --- a/packages/tui/examples/tui_colorpicker.rs +++ b/packages/tui/examples/tui_colorpicker.rs @@ -8,8 +8,8 @@ fn main() { } fn app(cx: Scope) -> Element { - let hue = use_state(&cx, || 0.0); - let brightness = use_state(&cx, || 0.0); + let hue = use_state(cx, || 0.0); + let brightness = use_state(cx, || 0.0); let tui_query: &Query = cx.consume_context().unwrap(); // disable templates so that every node has an id and can be queried cx.render(rsx! { diff --git a/packages/tui/examples/tui_hover.rs b/packages/tui/examples/tui_hover.rs index 2037adae..ea4ef9af 100644 --- a/packages/tui/examples/tui_hover.rs +++ b/packages/tui/examples/tui_hover.rs @@ -17,20 +17,20 @@ fn app(cx: Scope) -> Element { 127 * b } - let q1_color = use_state(&cx, || [200; 3]); - let q2_color = use_state(&cx, || [200; 3]); - let q3_color = use_state(&cx, || [200; 3]); - let q4_color = use_state(&cx, || [200; 3]); + let q1_color = use_state(cx, || [200; 3]); + let q2_color = use_state(cx, || [200; 3]); + let q3_color = use_state(cx, || [200; 3]); + let q4_color = use_state(cx, || [200; 3]); let q1_color_str = to_str(q1_color); let q2_color_str = to_str(q2_color); let q3_color_str = to_str(q3_color); let q4_color_str = to_str(q4_color); - let page_coordinates = use_state(&cx, || "".to_string()); - let element_coordinates = use_state(&cx, || "".to_string()); - let buttons = use_state(&cx, || "".to_string()); - let modifiers = use_state(&cx, || "".to_string()); + let page_coordinates = use_state(cx, || "".to_string()); + let element_coordinates = use_state(cx, || "".to_string()); + let buttons = use_state(cx, || "".to_string()); + let modifiers = use_state(cx, || "".to_string()); let update_data = move |event: Event| { let mouse_data = event.inner(); diff --git a/packages/tui/examples/tui_task.rs b/packages/tui/examples/tui_task.rs index 32215c0b..31a1ec2f 100644 --- a/packages/tui/examples/tui_task.rs +++ b/packages/tui/examples/tui_task.rs @@ -5,9 +5,9 @@ fn main() { } fn app(cx: Scope) -> Element { - let count = use_state(&cx, || 0); + let count = use_state(cx, || 0); - use_future(&cx, (), move |_| { + use_future(cx, (), move |_| { let count = count.to_owned(); let update = cx.schedule_update(); async move { diff --git a/packages/tui/examples/tui_text.rs b/packages/tui/examples/tui_text.rs index dfbf6e4d..a6662da8 100644 --- a/packages/tui/examples/tui_text.rs +++ b/packages/tui/examples/tui_text.rs @@ -5,7 +5,7 @@ fn main() { } fn app(cx: Scope) -> Element { - let alpha = use_state(&cx, || 100); + let alpha = use_state(cx, || 100); cx.render(rsx! { div { diff --git a/packages/tui/src/query.rs b/packages/tui/src/query.rs index 3fbcc15f..64da8765 100644 --- a/packages/tui/src/query.rs +++ b/packages/tui/src/query.rs @@ -26,8 +26,8 @@ use crate::{layout_to_screen_space, TuiDom}; /// } /// /// fn app(cx: Scope) -> Element { -/// let hue = use_state(&cx, || 0.0); -/// let brightness = use_state(&cx, || 0.0); +/// let hue = use_state(cx, || 0.0); +/// let brightness = use_state(cx, || 0.0); /// let tui_query: Query = cx.consume_context().unwrap(); /// cx.render(rsx! { /// div{ diff --git a/packages/tui/tests/events.rs b/packages/tui/tests/events.rs index dfaedab4..c4be26e4 100644 --- a/packages/tui/tests/events.rs +++ b/packages/tui/tests/events.rs @@ -33,7 +33,7 @@ fn key_down() { dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless()); fn app(cx: Scope) -> Element { - let render_count = use_state(&cx, || 0); + let render_count = use_state(cx, || 0); let tui_ctx: TuiContext = cx.consume_context().unwrap(); let render_count_handle = render_count.clone(); cx.spawn(async move { @@ -70,7 +70,7 @@ fn mouse_down() { dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless()); fn app(cx: Scope) -> Element { - let render_count = use_state(&cx, || 0); + let render_count = use_state(cx, || 0); let tui_ctx: TuiContext = cx.consume_context().unwrap(); let render_count_handle = render_count.clone(); cx.spawn(async move { @@ -104,7 +104,7 @@ fn mouse_up() { dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless()); fn app(cx: Scope) -> Element { - let render_count = use_state(&cx, || 0); + let render_count = use_state(cx, || 0); let tui_ctx: TuiContext = cx.consume_context().unwrap(); let render_count_handle = render_count.clone(); cx.spawn(async move { @@ -143,7 +143,7 @@ fn mouse_enter() { dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless()); fn app(cx: Scope) -> Element { - let render_count = use_state(&cx, || 0); + let render_count = use_state(cx, || 0); let tui_ctx: TuiContext = cx.consume_context().unwrap(); let render_count_handle = render_count.clone(); cx.spawn(async move { @@ -182,7 +182,7 @@ fn mouse_exit() { dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless()); fn app(cx: Scope) -> Element { - let render_count = use_state(&cx, || 0); + let render_count = use_state(cx, || 0); let tui_ctx: TuiContext = cx.consume_context().unwrap(); let render_count_handle = render_count.clone(); cx.spawn(async move { @@ -221,7 +221,7 @@ fn mouse_move() { dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless()); fn app(cx: Scope) -> Element { - let render_count = use_state(&cx, || 0); + let render_count = use_state(cx, || 0); let tui_ctx: TuiContext = cx.consume_context().unwrap(); let render_count_handle = render_count.clone(); cx.spawn(async move { @@ -260,7 +260,7 @@ fn wheel() { dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless()); fn app(cx: Scope) -> Element { - let render_count = use_state(&cx, || 0); + let render_count = use_state(cx, || 0); let tui_ctx: TuiContext = cx.consume_context().unwrap(); let render_count_handle = render_count.clone(); cx.spawn(async move { @@ -300,7 +300,7 @@ fn click() { dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless()); fn app(cx: Scope) -> Element { - let render_count = use_state(&cx, || 0); + let render_count = use_state(cx, || 0); let tui_ctx: TuiContext = cx.consume_context().unwrap(); let render_count_handle = render_count.clone(); cx.spawn(async move { @@ -339,7 +339,7 @@ fn context_menu() { dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless()); fn app(cx: Scope) -> Element { - let render_count = use_state(&cx, || 0); + let render_count = use_state(cx, || 0); let tui_ctx: TuiContext = cx.consume_context().unwrap(); let render_count_handle = render_count.clone(); cx.spawn(async move { diff --git a/packages/web/src/dom.rs b/packages/web/src/dom.rs index d48b6df3..0cdf46b3 100644 --- a/packages/web/src/dom.rs +++ b/packages/web/src/dom.rs @@ -7,13 +7,12 @@ //! - tests to ensure dyn_into works for various event types. //! - Partial delegation?> -use dioxus_core::{ElementId, Mutation, Mutations, Template, TemplateAttribute, TemplateNode}; +use dioxus_core::{Mutation, Template}; use dioxus_html::{event_bubbles, CompositionData, FormData}; use dioxus_interpreter_js::Interpreter; use futures_channel::mpsc; -use js_sys::Function; use std::{any::Any, rc::Rc}; -use wasm_bindgen::{closure::Closure, JsCast, JsValue}; +use wasm_bindgen::{closure::Closure, JsCast}; use web_sys::{Document, Element, Event}; use crate::Config; @@ -61,7 +60,7 @@ impl WebsysDom { let i = &self.interpreter; for edit in edits.drain(..) { match edit { - AppendChildren { id, m } => i.AppendChildren(m as u32), + AppendChildren { id, m } => i.AppendChildren(m as u32, id.0 as u32), AssignId { path, id } => i.AssignId(path, id.0 as u32), CreatePlaceholder { id } => i.CreatePlaceholder(id.0 as u32), CreateTextNode { value, id } => i.CreateTextNode(value.into(), id.0 as u32), @@ -81,7 +80,7 @@ impl WebsysDom { i.SetBoolAttribute(id.0 as u32, name, value) } SetText { value, id } => i.SetText(id.0 as u32, value.into()), - NewEventListener { name, scope, id } => { + NewEventListener { name, id, .. } => { self.interpreter.NewEventListener( name, id.0 as u32, diff --git a/packages/web/src/lib.rs b/packages/web/src/lib.rs index 399dfbce..62a2bf4d 100644 --- a/packages/web/src/lib.rs +++ b/packages/web/src/lib.rs @@ -53,15 +53,11 @@ // - Do the VDOM work during the idlecallback // - Do DOM work in the next requestAnimationFrame callback -use std::time::Duration; - pub use crate::cfg::Config; use crate::dom::virtual_event_from_websys_event; pub use crate::util::use_eval; use dioxus_core::{Element, ElementId, Scope, VirtualDom}; -use futures_channel::mpsc::unbounded; use futures_util::{pin_mut, FutureExt, StreamExt}; -use gloo_timers::future::sleep; mod cache; mod cfg; @@ -181,7 +177,7 @@ pub async fn run_with_props(root: fn(Scope) -> Element, root_prop wasm_bindgen::intern(s); } - let should_hydrate = cfg.hydrate; + let _should_hydrate = cfg.hydrate; let (tx, mut rx) = futures_channel::mpsc::unbounded(); @@ -193,8 +189,6 @@ pub async fn run_with_props(root: fn(Scope) -> Element, root_prop // } else { let edits = dom.rebuild(); - log::debug!("Initial edits {:#?}", edits); - websys_dom.load_templates(&edits.templates); websys_dom.apply_edits(edits.edits); @@ -214,9 +208,8 @@ pub async fn run_with_props(root: fn(Scope) -> Element, root_prop futures_util::select! { _ = work => None, - new_template = hotreload_rx.next() => { + _new_template = hotreload_rx.next() => { todo!("Implement hot reload"); - None } evt = rx.next() => evt } @@ -251,8 +244,6 @@ pub async fn run_with_props(root: fn(Scope) -> Element, root_prop // wait for the animation frame to fire so we can apply our changes work_loop.wait_for_raf().await; - log::debug!("edits {:#?}", edits); - websys_dom.load_templates(&edits.templates); websys_dom.apply_edits(edits.edits); } diff --git a/translations/pt-br/README.md b/translations/pt-br/README.md index 5acb13fa..ef14a1af 100644 --- a/translations/pt-br/README.md +++ b/translations/pt-br/README.md @@ -56,7 +56,7 @@ ```rust fn app(cx: Scope) -> Element { - let mut count = use_state(&cx, || 0); + let mut count = use_state(cx, || 0); cx.render(rsx! { h1 { "High-Five counter: {count}" }