Skip to content

What does the callback given to Scope::context do? #3349

Discussion options

You must be logged in to vote

The callback notifies you when the context value changes. The new value is being passed, so that you can react to the change and recompute values that depend on it.

In struct components, by default, the context changing does not result in a render of the component. It is expected that you send a message to your own component if you want to change state and use the message processing to notify yew that the component should be re-rendered.

In function components, the usage of use_context will schedule a re-render of the component every time the context changes, at which point you will receive the new context value from the hook during the function component render.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@JustAnotherCodemonkey
Comment options

@JustAnotherCodemonkey
Comment options

Answer selected by JustAnotherCodemonkey
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