question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Q: Why is emotion necessary with CRA?

See original GitHub issue

The top of the readme there is the following simple way which is absolutely amazing at a first sight.

import tw from 'twin.macro'

const default () => <input tw="border hover:border-black" />

Furthermore, there is also this sentence which would give me the impression that without conditionals I can use macro only.

For features like conditional styling and vanilla css, Twin works with styling libraries like 👩‍🎤 emotion or 💅 styled-components

Unfortunately, when I try that in a clean CRA project, the output I get is like this and that’s where the magical feeling is kinda lost.

<input css="[object Object]" />

To make that work I have to include this ceremony in each file that needs some styling.

/** @jsx jsx */
import { jsx } from '@emotion/core'
import tw from 'twin.macro'

Is there some better way I am simply not seeing?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
danielkczcommented, May 7, 2020

Thanks for the recommendation, but I am not a big fan of abstracting every little piece into a separate component. Ultimately, it creates a bigger mess than it solves imo. Of course, it makes sense for some frequently used parts, no argument there.

Consider this example I found somewhere around here. If I would be doing tw.div for each one of them then I am kinda losing a big benefit of TW - coming up with clever names for styled pieces of markup. So yea, in cases like that I would rather have two unused imports than bunch of styled components.

    <div tw="max-w-md mx-auto flex p-6 bg-gray-100 mt-10 rounded-lg shadow-xl">
      <div tw="ml-6 pt-1">
        <h1 tw="text-2xl text-blue-700 leading-tight">
          Tailwind and Create React App
        </h1>
        <p tw="text-base text-gray-700 leading-normal">
          Building apps together
        </p>
      </div>
    </div>

Maybe it’s even better to have common parts in TW config, I am not that much experienced with TW yet to decide on that.

Feel free to close this unless you want to use this issue to track docs improvement.

2reactions
ben-rogersoncommented, May 10, 2020

I remember hitting this at one stage too. I’ll take a look at what’s possible when I’m working on the macro next 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the things you can: Emotion regulation is more ... - NCBI
Each study and a meta-analysis of the three studies revealed that CRA was associated with less depression for lower-SES but not higher-SES ...
Read more >
Why is Emotional Expression Important?
Helps see problems in a new light · Makes decision making and problem solving easier · Gets rid of the power of the...
Read more >
Mental functions eligibility - Disability tax credit (DTC)
Detailed eligibility criteria that may qualify you for the DTC in the mental functions category.
Read more >
Insomnia and Emotion Regulation: Recent Findings and ...
Additionally empirical evidence suggests that emotional dysregulation plays a crucial role in the onset and maintenance of psychopathological disorders.
Read more >
Module not found: Can't resolve '@emotion/react'
After installing the package a restart of npm might be needed. Just stop the server and run npm start . – Drubio. May...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found