From 0.19.0 to 0.20.0
New Hooks and Function Components API
The Function Components and Hooks API are re-implemented with a different mechanism:
- User-defined hooks are now required to have a prefix and must be marked with the
#[hook]
attribute. - Hooks will now report compile errors if they are not called from the top level of a function component or a user defined hook. The limitation existed in the previous version of Yew as well. In this version, It is reported as a compile time error.
The scheduler now shedules its start to the end of the browser event loop. All messages queued during in the meantime will be run in batch. The running order of messages between components are no longer guaranteed, but messages sent to the same component is still acknowledged in an FIFO order. If multiple updates will result in a render, the component will be rendered once.
What this means to developers?
For struct components, this means that if you send 2 messages to 2 different components, they will not be guaranteed to be seen in the same order they are sent. If you send 2 messages to the same component, they will still be passed to the component in the order they are sent. The messages are not sent to the component immediately so you should not assume that when the component receives a message it still has the same state at the time the message is created.
Yew Renderer
start_app*
has been replaced by yew::Renderer
.
You need to enable feature to use yew::Renderer
.
For example, to use client side rendering to render a typical app component:
For more options, see the docs.
Previously node ref passed to a component was bound to the first element rendered by it. If this behavior is still desired, it is recommended to use add a r#ref
field to the component’s properties and bind it manually
changed
Method on Components
The method has now a new argument to provide the old properties to the function.
The old method’s signature was:
The new method’s signature is now: