--- title: 'Generic Components' description: 'The #[function_component] attribute' --- import Tabs from '@theme/Tabs' import TabItem from '@theme/TabItem' The `#[function_component]` attribute also works with generic functions for creating generic components. ```rust use std::fmt::Display; use yew::{function_component, html, Properties, Html, ToHtml}; #[derive(Properties, PartialEq)] pub struct Props where T: PartialEq, { data: T, } #[function_component] pub fn MyGenericComponent(props: &Props) -> Html where T: PartialEq + ToHtml, { html! {

{ &props.data }

} } // then can be used like this html! { data=123 /> }; // or html! { data={"foo".to_string()} /> }; ```