This is outdated documentation for Sycamore.
For up-to-date documentation, see the latest version (v0.8).
Components
Components in sycamore
are structs that implement Component
. A component can automatically be
created with the #[component(ComponentName<G>)]
attribute on a function.
Components receive their props through function arguments.
For components to automatically react to prop changes, they should accept a prop with type
StateHandle<T>
and call the function in the template!
to subscribe to the state. A
StateHandle<T>
is just a readonly Signal<T>
.
Getting a StateHandle<T>
from a Signal<T>
is easy. Just call the .handle()
method.
Here is an example of a simple component that displays the value of its prop:
use *;
// ...
let state = new;
template!
state.set; // automatically updates value in Component