diff --git a/packages/dioxus/src/launch.rs b/packages/dioxus/src/launch.rs index 2ab660e62..212a1f0fb 100644 --- a/packages/dioxus/src/launch.rs +++ b/packages/dioxus/src/launch.rs @@ -27,6 +27,22 @@ impl LaunchBuilder { } } + #[cfg(feature = "fullstack")] + /// Inject state into the root component's context that is created on the thread that the app is launched on. + pub fn context_provider(mut self, state: impl Fn() -> Box + Send + 'static) -> Self { + self.contexts + .push(Box::new(state) as Box Box + Send>); + self + } + + #[cfg(not(feature = "fullstack"))] + /// Inject state into the root component's context that is created on the thread that the app is launched on. + pub fn context_provider(mut self, state: impl Fn() -> Box + 'static) -> Self { + self.contexts + .push(Box::new(state) as Box Box>); + self + } + #[cfg(feature = "fullstack")] /// Inject state into the root component's context. pub fn context(mut self, state: impl Any + Clone + Send + 'static) -> Self {