You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Qwik, className is deprecated and we are encouraged to use class.
This is great news.
But when we want to create a component:
const Card = ({ class }) => {
return <div class={class}>I am a card</div>
}
Then the code does not compile.
We can easily change the name to style:
const Card = ({ style }) => {
But this means that our code is not consistent anymore. In some places, we apply styles using class and in some places, we apply styles using any other name that we have given to our parameters.
What is the solution here? How can we be consistent across a Vite JSX project to apply styles? Please specify your solution in the documentation.
Now you should see the QWIK WARN jsx: className is deprecated. Use class instead. warning
If you rename all of the className instances to class that warning goes away.
But now, how should we define the src/components/message.tsx component and take the class parameters?
In src/components/message.tsx if you uncomment the class parameter, then the code won't compile
The text was updated successfully, but these errors were encountered:
Nefcanto
changed the title
[📖] How to author components that accept style
[📖] How to author components that accept style, what name should be used instead of className?
Dec 31, 2022
Hi @Nefcanto
Thanks for creating this issue 🙏
The problem is not qwik related but a general JS "issue". Reserved keywords like class, const, let, var, etc. are not allowed to be used as variables.
here a short example:
function test(class) {
console.log(class);
}
test('foo');
so my suggestion would be what @jordanw66 already wrote or add an alias on the destructuring like this:
Suggestion
In Qwik,
className
is deprecated and we are encouraged to useclass
.This is great news.
But when we want to create a component:
Then the code does not compile.
We can easily change the name to
style
:But this means that our code is not consistent anymore. In some places, we apply styles using
class
and in some places, we apply styles using any other name that we have given to our parameters.What is the solution here? How can we be consistent across a Vite JSX project to apply styles? Please specify your solution in the documentation.
This is a minimal reproducible example. Steps to reproduce:
npm install
npm run dev
QWIK WARN jsx: className is deprecated. Use class instead.
warningclassName
instances toclass
that warning goes away.src/components/message.tsx
component and take theclass
parameters?src/components/message.tsx
if you uncomment theclass
parameter, then the code won't compileThe text was updated successfully, but these errors were encountered: