<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vladimír Gál</title>
    <description>The latest articles on DEV Community by Vladimír Gál (@mrdreix).</description>
    <link>https://dev.to/mrdreix</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F310630%2F35c52c3a-9204-47ae-91cf-e21250811621.jpg</url>
      <title>DEV Community: Vladimír Gál</title>
      <link>https://dev.to/mrdreix</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mrdreix"/>
    <language>en</language>
    <item>
      <title>How to use classes correctly in Qwik</title>
      <dc:creator>Vladimír Gál</dc:creator>
      <pubDate>Wed, 08 Feb 2023 09:16:39 +0000</pubDate>
      <link>https://dev.to/mrdreix/how-to-use-classes-correctly-in-qwik-3omi</link>
      <guid>https://dev.to/mrdreix/how-to-use-classes-correctly-in-qwik-3omi</guid>
      <description>&lt;p&gt;Recently, I encountered a problem with style classes while learning and coding a Qwik application and I believe it would be beneficial to share my knowledge with the community.&lt;/p&gt;

&lt;p&gt;I spent quite some time debugging this before finding out where the problem is and that it is not properly documented anywhere in the documentation, even though it is there ("kinda").&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The problem&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Qwik uses &lt;code&gt;class&lt;/code&gt; keyword while specifying styles instead of &lt;code&gt;className&lt;/code&gt;. Problem with this is that you can still use &lt;code&gt;className&lt;/code&gt;, in development mode. Qwik will give you warning that &lt;code&gt;className&lt;/code&gt; is deprecated, but you can still use it. In production build, Qwik will only apply styles to those components that are styled with the &lt;code&gt;class&lt;/code&gt; keyword. It will still leave the &lt;code&gt;className&lt;/code&gt; there, without any styling being applied to your component.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;The solution&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;While writing this blog post I was thinking about what can I give back to community to prevent this from happening to anyone else. Of course I can say: "Just don't use the &lt;code&gt;className&lt;/code&gt;", but we are all human beings. People can error. And to save you some time during development in Qwik, I've created this small eslint plugin you can use:&lt;br&gt;
&lt;a href="https://github.com/vladimirgal1012/eslint-plugin-qwik-additions"&gt;https://github.com/vladimirgal1012/eslint-plugin-qwik-additions&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;Installation&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Ensure your project uses eslint&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install &lt;code&gt;Qwik Additions&lt;/code&gt; eslint plugin:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i eslint-plugin-qwik-additions &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
yarn add &lt;span class="nt"&gt;-D&lt;/span&gt; eslint-plugin-qwik-additions
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Enable the plugin in .eslintrc.js:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//...your config&lt;/span&gt;
&lt;span class="nl"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;qwik-additions&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;,...&lt;/span&gt;&lt;span class="nx"&gt;yourPlugins&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="c1"&gt;//...your config&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Enable the &lt;code&gt;forbid-class-name&lt;/code&gt; rule (I've used error level, this will ensure that you won't build your application while having any component using &lt;code&gt;className&lt;/code&gt; keyword):&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//...your config&lt;/span&gt;
&lt;span class="nl"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//...your rules&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;qwik-additions/forbid-class-name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;error&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="c1"&gt;//...your config&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In today's blog post I explained a problem with using classes in Qwik and how to prevent it from happening. This was my first blog post ever, thanks for reading everyone :)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>qwik</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
