Files
dioxus/docs/guide/src/en/__unused/advanced-guides/06-subscription-api.md
T
Marc Espín 98fc153152 Fix: Remove play button from guide example (#1118)
* fix: Remove play button from guide example

* Update index.md

* update other examples
2023-06-28 09:32:42 -05:00

1.1 KiB

Subscriptions

Yew subscriptions are used to schedule update for components into the future. The Context object can create subscriptions:

fn Component(cx: Component) -> DomTree {
    let update = cx.schedule();

    // Now, when the subscription is called, the component will be re-evaluated
    update.consume();
}

Whenever a component's subscription is called, the component will then re-evaluated. You can consider the input properties of a component to be just another form of subscription. By default, the Dioxus component system automatically diffs a component's props when the parent function is called, and if the props are different, the child component's subscription is called.

The subscription API exposes this functionality allowing hooks and state management solutions the ability to update components whenever some state or event occurs outside of the component. For instance, the use_context hook uses this to subscribe components that use a particular context.

fn use_context<I>(cx: Scope<T>) -> I {

}