{"record":{"id":"4ab4656b77d7e04d","repo":"DioxusLabs/dioxus","slug":"could-not-find-context","errorCode":null,"errorMessage":"Could not find context {}","messagePattern":"Could not find context (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/global_context.rs","lineNumber":51,"sourceCode":"/// Try to consume context from the current scope, returning `None` if not found.\n///\n/// Unlike `use_context`, this is **not** a hook. It reads the context value directly from the\n/// runtime each time it is called, rather than caching it on first render. This means it can be\n/// called from anywhere the Dioxus runtime is active — inside event handlers, async tasks, spawned\n/// futures, or other non-hook contexts — without following the rules of hooks.\npub fn try_consume_context<T: 'static + Clone>() -> Option<T> {\n    Runtime::with_current_scope(|cx| cx.consume_context::<T>())\n}\n\n/// Consume context from the current scope, panicking if not found.\n///\n/// Unlike `use_context`, this is **not** a hook. It reads the context value directly from the\n/// runtime each time it is called, rather than caching it on first render. This means it can be\n/// called from anywhere the Dioxus runtime is active — inside event handlers, async tasks, spawned\n/// futures, or other non-hook contexts — without following the rules of hooks.\npub fn consume_context<T: 'static + Clone>() -> T {\n    Runtime::with_current_scope(|cx| cx.consume_context::<T>())\n        .unwrap_or_else(|| panic!(\"Could not find context {}\", std::any::type_name::<T>()))\n}\n\n/// Consume context from the current scope\npub fn consume_context_from_scope<T: 'static + Clone>(scope_id: ScopeId) -> Option<T> {\n    Runtime::current()\n        .try_get_state(scope_id)\n        .and_then(|cx| cx.consume_context::<T>())\n}\n\n/// Check if the current scope has a context\npub fn has_context<T: 'static + Clone>() -> Option<T> {\n    Runtime::with_current_scope(|cx| cx.has_context::<T>())\n}\n\n/// Provide context to the current scope\npub fn provide_context<T: 'static + Clone>(value: T) -> T {\n    Runtime::with_current_scope(|cx| cx.provide_context(value))\n}","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/24f6a829df0dfa203961a98ea4cae21c2ff27e28/packages/core/src/global_context.rs#L33-L69","documentation":"consume_context looked up a context of the requested type in the current scope's runtime and found none. A provider for that type must exist in an ancestor scope (via provide_context) before it can be consumed; a missing or differently-typed provider causes this failure.","triggerScenarios":"Thrown at packages/core/src/global_context.rs:51 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide the context in an ancestor component with use_context_provider before consuming it with use_context or try_use_context."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"24f6a829df0dfa203961a98ea4cae21c2ff27e28","analyzedAt":"2026-08-23T07:10:14.078Z","contentChangedAt":"2026-08-23T07:10:14.078Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}