Comments (4)
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.
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.
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.
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)
- Add early error to disallow invalid adjacent JSX elements HOT 3
- can you provide a syntactic sugar? HOT 3
- Can we move JSX to be an extension of ES Spec that evolves forward like EcmaScript + TC39 ? HOT 3
- RFC: An evolved JSX 2.0 proposal HOT 1
- Get accessor in props HOT 1
- HTML and JSX spec HOT 1
- The syntax in website is missing JSXFragment as JSXChild
- Proposal: ability to return multiple chlidren by auto-wraping them into a Fragment HOT 2
- Proposal: using ! prefix on attributes to set them to `false`
- Ambiguous syntax HOT 2
- Spec out whitespacing / line break behaviors HOT 4
- Split Out Lexical Grammar
- Behavior of `�` and lone surrogates unicode entities HOT 2
- Proposal: Attributes with the same name as their value HOT 1
- Proposal: Syntactic sugar for props with same name as value passed HOT 1
- Distinguish tags from elements in the terminology
- Feature request: nameless closing tags
- Proposal: faster way to id and classes HOT 7
- Proposal: combining classes using only className HOT 2
- In this specification there is a reference to Babylon, now @babel-parser
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsx.