How to use the emotion.cache function in emotion

To help you get started, we’ve selected a few emotion examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cdonohue / benefit / scripts / css.js View on Github external
.map((utility) => {
    // Call `styleWith` as if it was being used & extract the non-reset class
    // (e.g. `css-1234`)
    const [, emotionclassName] = benefit.styleWith(utility).split(" ")

    // Remove the `css-` prefix
    // (e.g. `1234`)
    const [, hash] = emotionclassName.split("-")

    // Get the rule as it would be inserted
    // e.g. css-1234:hover{opacity:0;}
    const inserted = emotion.cache.inserted[hash]

    // Replae `css-1234` with `hover:opacity-0`
    return inserted.replace(
      emotionclassName,
      utility.replace(":", "\\:").replace("/", "\\/")
    )
  })
  .join("\n")