Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoped css? #94

Closed
chenglou opened this issue Jun 15, 2013 · 2 comments
Closed

Scoped css? #94

chenglou opened this issue Jun 15, 2013 · 2 comments

Comments

@chenglou
Copy link
Contributor

The way React renders DOM is really interesting. I was wondering if there's any plan to include a functionality that sets the style of the rendered content without css name pollution. Something like the following:

style: function() {
  return {
    fruit: {border: '1px solid black'}
  };
},
render: function() {
  return <div className="fruit">{'Hello'}</div>;
}

And initialize the style at the beginning by changing the key to something unique, say fruit-abrt2 (same for the rendered class name). Of course, then there's the concern that a css rule might not reach fruit anymore since the class name doesn't actually exists, but I see such a huge benefit here that I believe it's worth thinking over this and find a solution.

@jordwalke
Copy link
Contributor

Great intuition. Several of us have thought about this opportunity and are thinking about approaches very similar to what you suggest. One of the benefits of defining style rules and css class specifications in JavaScript, is that you can use the full power of JavaScript to define styles, which we already have ways to model dependencies for. We wouldn't need another language like SASS or Less. Also, as you mention, since we also own the rendering/abstraction framework, we can ensure that we don't polute the CSS namespace. We can also ensure that components don't target nodes/class names that should be considered an implementation detail (concern) of a deeper component.

@vjeux
Copy link
Contributor

vjeux commented Jul 21, 2013

You can do the following right now:

getStyle: function() {
  return {
    fruit: {border: '1px solid black'}
  }
},
render: function() {
  return <div style={this.getStyle()}>Hello</div>;
}

Let's close this out until someone comes with a real proposal :)

@vjeux vjeux closed this as completed Jul 21, 2013
bvaughn added a commit to bvaughn/react that referenced this issue Aug 13, 2019
Rename "owner stack" label to "rendered by"
taneliang referenced this issue in MLH-Fellowship/react Aug 17, 2020
Experimenting with CI configs to better support Stack Attack
taneliang referenced this issue in MLH-Fellowship/react Aug 19, 2020
Experimenting with CI configs to better support Stack Attack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants