Change context api to panic with nice error message

This commit is contained in:
Jonathan Kelley committed 2024-01-15 18:02:58 -08:00
1 parent ee5020c41f
commit 14651a3573
19 files changed
+96 -69

No files matched your search

+2 -2
View File
@@ -1,9 +1,9 @@
use dioxus_core::{prelude::consume_context, prelude::provide_root_context, use_hook};
use dioxus_core::{prelude::provide_root_context, prelude::try_consume_context, use_hook};
///
pub fn use_root_context<T: 'static + Clone>(new: impl FnOnce() -> T) -> T {
use_hook(|| {
consume_context::<T>()
try_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"))
})