Search code examples
rustrust-cargoyew

could not find yew in stylist


I'm new to rust and yew and trying to use stylist crate with yew but when I try to import styled_components, I am getting following error.

error[E0432]: unresolved import `stylist::yew`
 --> src\lib.rs:2:14
  |
2 | use stylist::yew::styled_component;
  |              ^^^ could not find `yew` in `stylist`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `hello-yew` due to previous error
2022-11-22T16:30:53.476368Z ERROR  error
error from HTML pipeline

Has anyone seen this issue before?

I tried to delete previous stylist crates and tried to re-install the crate again but faced same issue.


Solution

  • From the docs:

    Yew Integration

    To enable yew integration. Enable feature yew_integration in Cargo.toml.

    You can create a style and use it with yew like this:

    use yew::prelude::*;
    use stylist::yew::styled_component;
    
    #[styled_component(MyStyledComponent)]
    fn my_styled_component() -> Html {
        html! {<div class={css!("color: red;")}>{"Hello World!"}</div>}
    }