Skip to content

Client-side global asyncronous state #3996

Answered by DogeDark
ActuallyHappening asked this question in Q&A
Discussion options

You must be logged in to vote

You can put signals inside of context which can be modified and react to changes.

Just make sure that the signals have the same scope as the context. (e.g. use_root_context will need Signal::new_in_scope(ScopeId::ROOT)) - I would instead suggest creating the context and signals in the same scope, such as the top-level App component, to avoid that issue.

e.g.

fn main() {
    dioxus::launch(App);
}

#[derive(Clone, Copy)]
struct ToggleCtx {
    toggled: Signal<bool>,
}

#[component]
fn App() -> Element {
    let toggle_ctx = use_context_provider(|| ToggleCtx { toggled: Signal::new(false) });
    let value = (toggle_ctx.toggled)();
    rsx! {
        "Is toggled: {value}",
        ToggleButton 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ActuallyHappening
Comment options

Answer selected by ActuallyHappening
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants