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
@@ -28,6 +28,15 @@ use wry::webview::WebView;
|
||||
|
||||
pub type ProxyType = EventLoopProxy<UserWindowEvent>;
|
||||
|
||||
/// Get an imperative handle to the current window without using a hook
|
||||
///
|
||||
/// ## Panics
|
||||
///
|
||||
/// This function will panic if it is called outside of the context of a Dioxus App.
|
||||
pub fn window() -> DesktopContext {
|
||||
dioxus_core::prelude::consume_context().unwrap()
|
||||
}
|
||||
|
||||
/// Get an imperative handle to the current window
|
||||
pub fn use_window(cx: &ScopeState) -> &DesktopContext {
|
||||
cx.use_hook(|| cx.consume_context::<DesktopContext>())
|
||||
|
||||
Reference in new issue
Block a user