Feat: add global context functions
Add functions like window() and router() to allow dynamically grabbing global contexts without have to use the hook variants. Deprecates the existing hook variants to discourage folks from adding more noise to their codebases.
This commit is contained in:
16 files changed
+77
-78
No files matched your search
+3
-8
@@ -1,7 +1,6 @@
|
||||
//! This example shows how to create a popup window and send data back to the parent window.
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_desktop::use_window;
|
||||
use futures_util::StreamExt;
|
||||
|
||||
fn main() {
|
||||
@@ -9,7 +8,6 @@ fn main() {
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let window = use_window(cx);
|
||||
let emails_sent = use_ref(cx, Vec::new);
|
||||
|
||||
let tx = use_coroutine(cx, |mut rx: UnboundedReceiver<String>| {
|
||||
@@ -34,7 +32,7 @@ fn app(cx: Scope) -> Element {
|
||||
// this returns a weak reference to the other window
|
||||
// Be careful not to keep a strong reference to the other window or it will never be dropped
|
||||
// and the window will never close.
|
||||
window.new_window(dom, Default::default());
|
||||
dioxus_desktop::window().new_window(dom, Default::default());
|
||||
},
|
||||
"Click to compose a new email"
|
||||
}
|
||||
@@ -57,7 +55,6 @@ struct ComposeProps {
|
||||
|
||||
fn compose(cx: Scope<ComposeProps>) -> Element {
|
||||
let user_input = use_state(cx, String::new);
|
||||
let window = use_window(cx);
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
@@ -66,15 +63,13 @@ fn compose(cx: Scope<ComposeProps>) -> Element {
|
||||
button {
|
||||
onclick: move |_| {
|
||||
cx.props.app_tx.send(user_input.get().clone());
|
||||
window.close();
|
||||
dioxus_desktop::window().close();
|
||||
},
|
||||
"Click to send"
|
||||
}
|
||||
|
||||
input {
|
||||
oninput: move |e| {
|
||||
user_input.set(e.value.clone());
|
||||
},
|
||||
oninput: move |e| user_input.set(e.value.clone()),
|
||||
value: "{user_input}"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user