<?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>Forem: fabiangamboa95</title>
    <description>The latest articles on Forem by fabiangamboa95 (@fabiangamboa95).</description>
    <link>https://forem.com/fabiangamboa95</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%2F612674%2F291939f8-fab5-4e59-a1df-f38c9f267132.jpeg</url>
      <title>Forem: fabiangamboa95</title>
      <link>https://forem.com/fabiangamboa95</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/fabiangamboa95"/>
    <language>en</language>
    <item>
      <title>Use Emotion with React Typescript ^4.1</title>
      <dc:creator>fabiangamboa95</dc:creator>
      <pubDate>Mon, 30 Aug 2021 04:29:10 +0000</pubDate>
      <link>https://forem.com/fabiangamboa95/use-emotion-with-react-typescript-4-1-2l3h</link>
      <guid>https://forem.com/fabiangamboa95/use-emotion-with-react-typescript-4-1-2l3h</guid>
      <description>&lt;h3&gt;
  
  
  Problem
&lt;/h3&gt;

&lt;p&gt;Hello friends. I just spend over 20mins searching for the right way to configure react-typescript to get the &lt;a href="https://emotion.sh/docs/introduction"&gt;emotion&lt;/a&gt; library working. And I couldn't find &lt;strong&gt;the single place&lt;/strong&gt; where the answer lies.&lt;br&gt;
So now that I gathered enough, you don't need to spend that time over such a simple issue.&lt;/p&gt;
&lt;h3&gt;
  
  
  Solution
&lt;/h3&gt;

&lt;p&gt;1 - After you install the proper package "@emotion/react". You need to head over your &lt;em&gt;tsconfig.json&lt;/em&gt; file and make sure you have the following lines under &lt;em&gt;"compilerOptions"&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    "jsx": "react-jsx",
    "jsxImportSource": "@emotion/react"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2 - Then as a requirement you must have &lt;em&gt;these&lt;/em&gt; "comments" at the top of every .tsx file you want to use the css functionality.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/** @jsxRuntime classic */
/** @jsx jsx */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3 - Don't forget to always &lt;strong&gt;import { jsx } from '@emotion/react'&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  A complete usage example would be:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/** @jsxRuntime classic */
/** @jsx jsx */
import { jsx, css } from "@emotion/react";

const App = () =&amp;gt; {
  return (
    &amp;lt;div
      css={css`
        padding: 32px;
        background-color: hotpink;
        font-size: 24px;
        border-radius: 4px;
        &amp;amp;:hover {
          color: ${color};
        }
      `}
    &amp;gt;Hover to change color.&amp;lt;/div&amp;gt;
  );
};

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There you go! If it was useful for you consider to smash that heart, that way I'll keep posting stuff.&lt;/p&gt;

</description>
      <category>react</category>
      <category>typescript</category>
      <category>emotion</category>
    </item>
  </channel>
</rss>
