Well, looking at the examples, it's easy to bind some functionality to a button. But how does one e.g. fetch data on page load?
Take the gravatar example:
In the gravatar message handling code, they create a callback which will be send back to the event look by the Env<Context>. This is given back to the context for fetching the gravatar data.
You also have a Env<Context> as well in the create function. Doing the equivalent will work, because this function will be called when your Component will be placed in the DOM. The rest of the Message handling can be adopted.
In the gravatar message handling code, they create a callback which will be send back
the link is missing, and another problem is that in the newest yew, we don't have Env<Context> anymore in the create function.
After I checked the code from gravatar handling, in fact the code fetch data after the component is created, but what we want is to load data from file when creating a component and make the data remain unchanged untill we reflesh the whole page. This use case is suitable for most website.
The dashboard example shows how to make fetch requests, although they are kicked off by a user action. In order to make it run as soon as the component is instantiated, move the relevant code inside update's FetchData variant to create or mounted to make it run immediately.
Most helpful comment
Take the gravatar example:
In the gravatar message handling code, they create a callback which will be send back to the event look by the
Env<Context>. This is given back to the context for fetching the gravatar data.You also have a
Env<Context>as well in the create function. Doing the equivalent will work, because this function will be called when your Component will be placed in the DOM. The rest of the Message handling can be adopted.