Skip to content

Change to #[styled] #[function_component] #150

@kirillsemyonkin

Description

@kirillsemyonkin

Change #[styled_component] to no longer be a #[function_component] wrapper, and to become a simple function body modifier #[styled] instead.

Breaking changes; low or medium priority. Discussion is not required, PRs can be done either by stylist devs, me, or someone else in the community.

Description

As yew-autoprops 0.4 released, we have been greeted with the following syntax:

#[autoprops]
#[function_component]
pub fn AutopropsComponent() -> Html { ... }

Autoprops only touches props and the function body (to add some implicit clones in front). Assuming #[styled_component] also only slightly modifies the component body, it appears to be changeable to use the same model (becoming #[styled]) with still being able to be compatible with autoprops in either of those two configurations:

#[autoprops]
#[styled]
#[function_component]
pub fn StyledComponent1() -> Html { ... }

#[styled]
#[autoprops]
#[function_component]
pub fn StyledComponent2() -> Html { ... }

Note

With yew #3347, the whole chain will look like #[styled] #[autoprops] #[component] or #[autoprops] #[styled] #[component].

Benefits

  • Shows great future for composability of such procedural macros.
  • Will give #[styled] to have an easy way to write down some custom options for it (if that will ever be needed).
  • Consistency with #[autoprops] - this one is fully up to stylist to decide, its just a bonus lol
  • Changes are independent of Yew's slow development cycle, and can be implemented with a subsequent release at any point.
  • Will get rid of the need to fix up stylist upon yew #3347, since it will no longer contain references to #[function_component] in its code.

Drawbacks

  • Extra ] #[function for the users.
  • Generating #[function_component] ensured that the result will make a yew-compatible code. If stylist uses hooks in the generated body, it will have no proper way to check whether user used #[function_component], which may lead to a non-user-friendly error.

Alternative

Leave only autoprops supporting this. Following syntax should already work now:

#[autoprops]
#[styled_component]
pub fn StyledComponent() -> Html { ... }

Warning

Mind that yew #3347 will require a stylist change to use #[::yew::functional::component] or something similar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions