Skip to content

Instantly share code, notes, and snippets.

@manfromth3m0oN
Created March 23, 2022 23:00
Show Gist options
  • Save manfromth3m0oN/426e55b3961583aa3fa1ea79883fd890 to your computer and use it in GitHub Desktop.
Save manfromth3m0oN/426e55b3961583aa3fa1ea79883fd890 to your computer and use it in GitHub Desktop.
macro rules
use yew::prelude::*;
#[function_component(Navbar)]
fn child() -> Html {
return html! { "I am a child" };
}
macro_rules! todo_view {
($function:ident => $name:ident) => {
#[function_component($name)]
fn $function() -> Html {
return html! { "I am a " };
}
};
($($function:ident => $name:ident),+) => {
$(todo_view!($function => $name);)+
};
}
todo_view!(player => Player, people => People, playlist => Playlist, controls => Controls);
#[function_component(Root)]
fn root() -> Html {
return html! { <>
<Navbar/>
<Player/>
<People/>
<Playlist/>
<Controls/>
</>
};
}
fn main() {
yew::start_app::<Root>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment