What does the callback given to Scope::context do? #3349
-
This isn't explained in either the website standard docs or the api docs. In fact, neither give a reason to use it. It just is in one of the examples, specifically the child to grandparent message passing example. Can someone help explain this to me? I'm new to Yew. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
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 |
Beta Was this translation helpful? Give feedback.
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.