Attribute Macro ruukh_codegen::component
source · #[component]
Expand description
#[component]
macro to derive Component
trait as well as to do
modifications to the struct. It does all the heavy lifting which the user
would have to do, to make the component work.
Example
#[component]
struct MyButton {
disabled: bool,
}
You may declare events available on the component by placing #[events]
attribute. Like:
Example
#[component]
#[events(
fn event_name(&self, arg: type) -> return_type;
)]
struct MyButton {
disabled: bool,
}
You may place multiple event declarations. Also, these event declarations require that the event handlers be passed compulsorily.
#[component]
also allows to annotate the struct fields with additional
attributes. Such as:
-
#[prop]
attribute: This attribute defines that a field is a prop field, though this attribute is optional. This attribute allows passing a default value for the prop field. Like#[prop(default)]
which delegates it to the typesDefault
implementation or#[prop(default = val)]
which uses theval
as its default value. Any fields which has a givendefault
value or anyOption
type is optional while passing props. -
#[state]
attribute: This attributes is required to define a field as a state field. If a#[state]
or#[state(default)]
is specified then theDefault
value of the field is used. If you want to provide a more specific value, then pass it by using#[state(default = val)]
attribute.