How to render a function parameter #4270
-
Hi, I am a new user of Preact, I am trying to render a function parameter like this:
This line doesn't work |
Beta Was this translation helpful? Give feedback.
Answered by
marvinhagemeister
Feb 1, 2024
Replies: 1 comment 1 reply
-
JSX expects an identifier there and the name must start with an uppercase character to be detected as a component. function MyFunction({icon, text, color}) {
+ // Uppercase name so that transpiler can detect that it's a component
+ const IconComponent = icon;
+
return(
<span class={`... ${color} `}>
- {icon && <{icon} class="w-5 h-5"/>}
+ {IconComponent && <IconComponent class="w-5 h-5"/>}
<span class="...">{text}</span>
</span>
)
}; |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
marvinhagemeister
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JSX expects an identifier there and the name must start with an uppercase character to be detected as a component.