Component with Generic Type that has Generics Itself #3373
-
Hi All, I'm trying to construct something like this:
It seems that Leptos is unable to parse this. Is there any way to support this? A type alias appears to work, it is however not ideal. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
You are correct that this does not parse in the There are definitely ways to support it; whether you like them or not are another question.
#[component]
pub fn App() -> impl IntoView {
view! {
<p>"Some other content"</p>
{Component::<Vec<String>>()}
}
}
fn Component<T>() -> impl IntoView {}
#[component]
pub fn App() -> impl IntoView {
view! {
<Component marker={PhantomData::<Vec<String>>}/>
}
}
#[component]
fn Component<T>(#[prop(optional)] marker: PhantomData<T>) -> impl IntoView {}
|
Beta Was this translation helpful? Give feedback.
-
Hi, I found that I am facing somewhat the same issue as this one. What would be the solution if I had two generics instead? Something like this: #[component(transparent)]
pub fn GenericSeries<T, O>(
#[prop(optional)] options: Option<Signal<O>>,
data: Signal<Vec<T>>,
markers: Signal<Vec<Marker>>,
series_type: String,
) -> impl IntoView
where
T: Serialize + Clone + Send + Sync + 'static,
O: Serialize + Clone + Send + Sync + 'static,
{} |
Beta Was this translation helpful? Give feedback.
You are correct that this does not parse in the
view
macro, and it is a limitation of therstml
crate we use for parsing theview
macro.There are definitely ways to support it; whether you like them or not are another question.
PhantomData
marker, so you c…