<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Birgit Nehrwein on Medium]]></title>
        <description><![CDATA[Stories by Birgit Nehrwein on Medium]]></description>
        <link>https://medium.com/@nehrwein?source=rss-415799e4aec4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uPVQ9ifFnzHBwVHrrIvdcQ.jpeg</url>
            <title>Stories by Birgit Nehrwein on Medium</title>
            <link>https://medium.com/@nehrwein?source=rss-415799e4aec4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 08:42:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nehrwein/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Conditional Styling with Styled Components in React]]></title>
            <link>https://medium.com/@nehrwein/conditional-styling-with-styled-components-in-react-c26bd9f0db88?source=rss-415799e4aec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c26bd9f0db88</guid>
            <category><![CDATA[props]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[styled-components]]></category>
            <dc:creator><![CDATA[Birgit Nehrwein]]></dc:creator>
            <pubDate>Sun, 05 Dec 2021 20:12:55 GMT</pubDate>
            <atom:updated>2021-12-05T20:12:55.305Z</atom:updated>
            <content:encoded><![CDATA[<p>As I learn more about styled-components, I start using them for more advanced styling and do conditional styling with them in React. The syntax might look a bit scary in the beginning, but once you got the hang of it, it gives you a lot more possibilities to do conditional styling than CSS.</p><h3>A simple case</h3><p>Let’s say, we want to conditionally change the color of a div. It will be displayed green, if a task is completed and otherwise red.</p><p>We can use props and the ternary operator for the conditional styling in React. Like so ${props =&gt; props.completed ? &#39;green&#39; : &#39;red&#39;}</p><p>So let’s create two StyledDivs with a prop. You can call the prop however you want. Let’s call it “completed”. In the first case, completed is true and and the second case it’s false.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-29mHqUlWCglCU8rd4j5_A.png" /><figcaption>Example of conditional styling with props</figcaption></figure><p>The output will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*9TDePYFrHeXepnFbRONWRg.jpeg" /></figure><h3>Multiple conditions</h3><p>It’s simple to expand your code and use multiple conditions instead of a simple if/else-condition.</p><p>In the following example, Icreated three StyledDivs with the prop “category”. They will be displayed each with a different background-color according to which category they belong to. To achieve this, we only have to add more cases to our ternary operator in line 10–14.</p><p>Note that the fourth StyledDiv doesn’t belong to any category. It will get the default background-color “orange” defined in line 14.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*k5bNQ5gsGBnzNTCH93U40g.png" /></figure><p>This will be the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*G8GGZq0PWkl2kQ-AJtt_qg.jpeg" /></figure><p>You can do this with any CSS property you want and there are endless possibilities how to use great feature of styled-components.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c26bd9f0db88" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to start working with Styled Components in React]]></title>
            <link>https://medium.com/@nehrwein/how-to-start-working-with-styled-components-in-react-e057e48383a5?source=rss-415799e4aec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/e057e48383a5</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[styled-components]]></category>
            <dc:creator><![CDATA[Birgit Nehrwein]]></dc:creator>
            <pubDate>Sun, 07 Nov 2021 12:17:21 GMT</pubDate>
            <atom:updated>2021-11-07T12:26:25.770Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently learned about styled-components and how to use them. In this article I want to share my insights of how to overcome some common struggles, if you are new to styled-components. I really like the concept of this React library that allows you to do the styling directly in your React component. So, what are the benefits?</p><h3>The Benefits of using Styled Components</h3><ul><li>Well first of all, you have all the code concerning a component in one place. No jumping back and forth between different files any longer.</li><li>It makes your code very organized and if you decide to no longer use a component, you just remove it from your code-files. There’s no dead code elimination in the CSS needed.</li><li>All JavaScript functionalities are available to you. You can use if-statements, calculate and access different variables. It’s easy to customize your code by using JavaScript props.</li></ul><h3>The Downsides (Spoiler: There aren’t any)</h3><p>In my opinion there’s nothing that should stop you from using styled-components as long as you set up your system in a smooth way.</p><h4>Dev-Tools behaviour</h4><p>When you start working with styled-components, you will quickly notice, that you can’t identify your html-elements by class-names any longer. That’s quite annoying, when you want to work in the dev-tools. Fortunately there is a fix for that:</p><ul><li>Install the Babbel plug in: npm install --save-dev babel-plugin-styled-components</li><li>if you are using create-react-app then you should use import styled from &#39;styled-components/macro&#39;; instead of import styled from &#39;styled-components&#39;; inside your component. <a href="https://styled-components.com/docs/tooling">More Details</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*4MUJiedNR37NQEhkzShV6Q.png" /><figcaption>Dev-tools showing styled-components-name as class-name</figcaption></figure><h4>Syntax</h4><p>Styled-components require writing pseudo CSS code in backticks (``) which makes VSCode treat them as a string. And therefore you lose the CSS-syntax-highlighting and auto-complete. In order to gain it back, you should install this <a href="https://marketplace.visualstudio.com/items?itemName=jpoissonnier.vscode-styled-components">extension</a> for VSCode and everything looks like you are used from your CSS-files again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*S_5auHCS8jrgh93ys_ILxw.png" /><figcaption>CSS-syntax-highlighting on styled-components</figcaption></figure><h3>How to deal with …</h3><p>With styled-components you will do all your CSS-magic in one place, so here are some ways to apply additional styling like hover effects and animations to your code.</p><h4>… hover effects?</h4><p>Just add &amp;:hover {//your CSS};to your styled-component</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*eaZSydRzHyeFB34QSMe1fQ.png" /><figcaption>Hover-effect in styled-component</figcaption></figure><h4>… media queries?</h4><p>You can use Media queries the same way as you would do it in CSS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*ky4yFic_R32_EDPDes3H8A.png" /><figcaption>Media Queries in styled-components</figcaption></figure><h4>… animations?</h4><ol><li>Start by importing keyframes from the library like this:</li></ol><p>import styled, { keyframes } from &quot;styled-components&quot; (or from &quot;styled-components/macro&quot; if you work with create-react-app)</p><p>2. Define the animation pretty much like any other component:</p><p>const YourAnimation = keyframes ` //Your CSS`</p><p>3. And finally call the animation like this:</p><p>animation: ${YourAnimation} duration ...;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bJUPejsEPyu13C1dLhIs2Q.png" /></figure><h3>That’s it!</h3><p>Applying these concepts of styled-components will hopefully help to get you started.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e057e48383a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>