How to create a generic Input when passing prop `class` to override styles?
Hi,
I'm trying to create a generic input. I'm using Tailwindcss for the styling with
cva
(class-variance-authority) which allows me to create variants.
I want to allow users to pass class
to override the input.
I have this component:
Ant then I call the component like so
The problem here is that if I try to extract class
from props const { size, class, ...inputProps } = merged;
I get an error: Unexpected keyword 'class'. I know that class is a reserved word in JavaScript. However, if I try to use className
then I get this error: Property 'className' does not exist on type { ... };
Is there a way to pass a class or should I rename the prop as something else?3 Replies
Hi you can extract class by renaming it
then pass it like normal
But you still will have problem with reactivity if you destructure props like that, same with size=md should be in mergeProps. You can use built in solid helper something like this
then when rendering
Hi @maxoucsgo,
Thank you very much for your reply. I didn't know about
splitProps
, this solved my problem.Nice! np