Bring back mroe hooks, remove old hooks, cleanup a number of examples

This commit is contained in:
Jonathan Kelley committed 2024-01-15 17:04:39 -08:00
1 parent b291a5c0b0
commit 74aa55f85f
33 files changed
+179 -643

No files matched your search

+6 -5
View File
@@ -1,9 +1,10 @@
use dioxus_core::ScopeState;
use dioxus_core::{prelude::consume_context, prelude::provide_root_context, use_hook};
///
pub fn use_root_context<T: 'static + Clone>(, new: impl FnOnce() -> T) -> &T {
cx.use_hook(|| {
cx.consume_context::<T>()
.unwrap_or_else(|| cx.provide_root_context(new()))
pub fn use_root_context<T: 'static + Clone>(new: impl FnOnce() -> T) -> T {
use_hook(|| {
consume_context::<T>()
// If no context is provided, create a new one at the root
.unwrap_or_else(|| provide_root_context(new()).expect(" A runtime to exist"))
})
}