<?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: Tarek Campos</title>
    <description>The latest articles on DEV Community by Tarek Campos (@tarekcampossaleh).</description>
    <link>https://dev.to/tarekcampossaleh</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%2F634882%2F2c4f4055-7c96-4ba7-8a3a-eeeb37325d83.jpg</url>
      <title>DEV Community: Tarek Campos</title>
      <link>https://dev.to/tarekcampossaleh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tarekcampossaleh"/>
    <language>en</language>
    <item>
      <title>Getting rid of Next.js &amp; styled-components Warning: Prop `className` did not match </title>
      <dc:creator>Tarek Campos</dc:creator>
      <pubDate>Thu, 23 Sep 2021 02:11:19 +0000</pubDate>
      <link>https://dev.to/tarekcampossaleh/getting-rid-of-next-js-styled-components-warning-prop-classname-did-not-match-15ef</link>
      <guid>https://dev.to/tarekcampossaleh/getting-rid-of-next-js-styled-components-warning-prop-classname-did-not-match-15ef</guid>
      <description>&lt;p&gt;So, if you've been in touch with the Next.js + styled-components error: "Warning: Prop &lt;code&gt;className&lt;/code&gt; did not match", at development stage, here's a how to solve that problem.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OZQrdgwB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9bp8tn9wn4vd697f7f5r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OZQrdgwB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9bp8tn9wn4vd697f7f5r.png" alt="Error Image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This problem only occurs on development stage of Next.js enviroment basically because at the current version of Next.js (11.1.2), Next uses &lt;a href="https://babeljs.io/"&gt;Babel&lt;/a&gt; under the hood. &lt;/p&gt;

&lt;p&gt;And because of that, we need to inform the compiler that we're using the styled-component library, in a way to keep the stylized layout rendered at refresh time. &lt;/p&gt;

&lt;p&gt;For our own lucky, there is an easy way to solve that. With that in mind, lets add the babel-styled-components plugin, as you can see below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;yarn add babel-plugin-styled-components &lt;span class="nt"&gt;-D&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or in case you're using npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; babel-plugin-styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, at the root of our directory, lets create a &lt;code&gt;.babelrc&lt;/code&gt; file, then insert the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;presets&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next/babel&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="s2"&gt;plugins&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;styled-components&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ssr&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}]]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it, just restart the development build of Next in a way to babel see and apply the latest config, then it should be working 100% error-free.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>styledcomponents</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
