Coder Social home page Coder Social logo

Comments (4)

syranide avatar syranide commented on May 5, 2024 1

Unless it has been changed (don't think so), then you should use dangerouslySetInnerHTML with style for React, not provide a string child.

But to the point, with ES6 the solution to this is simple, use template strings:

<style>{`
  foo bar ${foobar} { .. }
`}</style>
var html = {_html: `
  foo bar ${foobar} { .. }
`};
<style dangerouslySetInnerHTML={html} />

from jsx.

giuseppeg avatar giuseppeg commented on May 5, 2024 1

Ideally it would be great if style's content could be parsed as TemplateLiteral when it is just text and doesn't start with {:

<style>
  div { color: red; }
  span { background: ${ color } }
</style>

// parsed like

<style>{`
  div { color: red; }
  span { background: ${ color } }
`}</style>

For styled-jsx this would be amazing.

from jsx.

Buslowicz avatar Buslowicz commented on May 5, 2024 1

Sorry for digging this up, but are there any plans to implement something to solve this? Custom delimiters would be great, or at least a way to specify which tags content should not be parsed.

from jsx.

sebmarkbage avatar sebmarkbage commented on May 5, 2024

The template literal solution indeed solve this. If we go down the route of #35 then the template literal solution might seem more natural to go for.

Although I might also suggest that we should support an object as the child of style in React which has all the selectors as properties. That is already how the style attribute works in React. It simply uses the existing syntax for data structures that already exist in JS.

<style>{{
  '*': {
    'background-color': 'red'
  }
}}</style>

This allows you to specify structured data that could even be type specific using CSSOM instead of having to parse a string.

from jsx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.