DioxusLabs / DioxusLabs/docsite
Dynamic Context pattern
- Dominant language
- Rust
- Stars
- 206
- Forks
- 208
- Avg merge
- 1h 11m
- Merged PRs (30d)
- 3
Description
The new context documentation talks about dynamically providing a theme pattern in event handlers: https://dioxuslabs.com/learn/0.7/essentials/basics/context#dynamically-providing-and-consuming-context
This seems difficult to use because context is not reactive. If you consume or try to consume the context in child components, you would need to manually rerun those child those child components when you provide the context. Should we recommend this pattern? Related to https://github.com/DioxusLabs/dioxus/issues/4509
Alternatively, maybe a more useful pattern we could recommend with these functions is dynamically providing the context if it doesn't already exist?
```rust
fn SharedSessionId() -> Element {
// Get the session id or create and provide one to the children if it doesn't exist
let session_id = use_hook(|| try_consume_context::>().unwrap_or_else(|| Signal::new(0)));
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.