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.

Custom "css" config isn't invoked when using tagged literals

See original GitHub issue

In an attempt to adapt twin to react native, I’ve configured it as follows:

{
  "babelMacros": {
    "twin":{
      ...
      "styled": {
        "import": "default",
        "from": "styled-components/native"
      },
      "css": {
         "import": "default",
         "from": "my-custom-thing"
      }
    }
  }
}

To illustrate: what I am expecting from this configuration is that when using twin for tagged literals like so tw`flex-1`; that the output is processed through my-custom-thing just like tw(View)`flex-1`; is processed through styled-components/native

Unfortunately, this is not the case as tw`flex-1`; will return the same value regardless of what I specify under the “css” property in my config.

This is critical for working with react-native as I need to use a custom function to transform raw css rules, like margin-top: 10px; to react-native compatible objects, like { marginTop: 10 }. As I am unsure how you architected this internally, I don’t know if there is any way to configure twin such that I have access to this processing step (or if this is a processing step at all).

I did notice, however, that import tw, { css } from 'twin.macro' imports my-custom-thing as css.

Hope this question is clear. Thank you!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JimmyLvcommented, Mar 9, 2021

With a couple custom plugins, I have twin working on react native!

Hi @edible-programs @ben-rogerson , could you please help to post the plugin code? 😁 Thanks

1reaction
ben-rogersoncommented, Sep 22, 2020

That’s great news, next time I’m making a native app this will come in handy 👍

It would be great to post your plugin code here so others can have a quicker setup.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[JavaScript] HTML and CSS syntax highlighting in tagged ...
The JS Custom extension isn't designed to apply arbitrary highlighting to regular, untagged templates. You probably wouldn't want all template ...
Read more >
Template literals (Template strings) - JavaScript | MDN
To supply a function of your own, precede the template literal with a function name; the result is called a tagged template.
Read more >
javascript - Problem with tagged template strings and closure
Symbol.toPrimitive method, invoked within tagged template literal loses access to the closure. To reproduce, simply paste the provided code ...
Read more >
8. Template literals - Exploring JS
Tagged template literals allow you to implement custom embedded sub-languages (which are sometimes called domain-specific languages) with little effort, ...
Read more >
Understanding Template Literals in JavaScript - DigitalOcean
In this article, you will go over the differences between single/double-quoted strings and template literals, running through the various ways ...
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